Dialer: Refactor FilteredNumbersUtil
* Since blocking is done via BlockedNumbersContract now, we don't need
the helper methods there anymore
* Move the rest related to emergency calls to a new class
Change-Id: I0a0f4e656a2a9a34412cb426c0a64bf2c90ade88
diff --git a/java/com/android/dialer/app/calllog/BlockReportSpamListener.java b/java/com/android/dialer/app/calllog/BlockReportSpamListener.java
index 450c914..6efdc62 100644
--- a/java/com/android/dialer/app/calllog/BlockReportSpamListener.java
+++ b/java/com/android/dialer/app/calllog/BlockReportSpamListener.java
@@ -17,6 +17,7 @@
package com.android.dialer.app.calllog;
import android.content.Context;
+import android.provider.BlockedNumberContract;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
@@ -103,18 +104,15 @@
final String countryIso,
final int callType,
final ContactSource.Type contactSourceType,
- final boolean isSpam,
- final Integer blockId) {
+ final boolean isSpam) {
DialogFragmentForUnblockingNumberAndReportingAsNotSpam.newInstance(
displayNumber,
isSpam,
() -> {
LogUtil.i("BlockReportSpamListener.onUnblock", "onClick");
- filteredNumberAsyncQueryHandler.unblock(
- (rows, values) -> {
- adapter.notifyDataSetChanged();
- },
- blockId);
+ if (BlockedNumberContract.unblock(context, number) > 0) {
+ adapter.notifyDataSetChanged();
+ }
},
null)
.show(fragmentManager, BlockReportSpamDialogs.UNBLOCK_DIALOG_TAG);
diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java
index 483b56b..866f4d7 100644
--- a/java/com/android/dialer/app/calllog/CallLogAdapter.java
+++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java
@@ -26,6 +26,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Trace;
+import android.provider.BlockedNumberContract;
import android.provider.CallLog;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.v7.app.AlertDialog;
@@ -79,9 +80,6 @@
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
-import com.google.i18n.phonenumbers.NumberParseException;
-import com.google.i18n.phonenumbers.PhoneNumberUtil;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
@@ -568,10 +566,6 @@
}
}
- public void clearFilteredNumbersCache() {
- filteredNumberAsyncQueryHandler.clearCache();
- }
-
public void onResume() {
if (PermissionsUtil.hasPermission(activity, android.Manifest.permission.READ_CONTACTS)) {
contactInfoCache.start();
@@ -747,17 +741,16 @@
// Reset block and spam information since this view could be reused which may contain
// outdated data.
viewHolder.isSpam = false;
- viewHolder.blockId = null;
+ viewHolder.isBlocked = false;
viewHolder.setDetailedPhoneDetails(callDetailsEntries);
final AsyncTask<Void, Void, Boolean> loadDataTask =
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
- viewHolder.blockId =
- filteredNumberAsyncQueryHandler.getBlockedIdSynchronous(
- viewHolder.number, viewHolder.countryIso);
- details.isBlocked = viewHolder.blockId != null;
+ viewHolder.isBlocked = BlockedNumberContract.canCurrentUserBlockNumbers(activity) &&
+ BlockedNumberContract.isBlocked(activity, viewHolder.number);
+ details.isBlocked = viewHolder.isBlocked;
if (isCancelled()) {
return false;
}
diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java
index 06d60b3..e60bbfa 100644
--- a/java/com/android/dialer/app/calllog/CallLogFragment.java
+++ b/java/com/android/dialer/app/calllog/CallLogFragment.java
@@ -400,11 +400,6 @@
this.hasReadCallLogPermission = hasReadCallLogPermission;
- /*
- * Always clear the filtered numbers cache since users could have blocked/unblocked numbers
- * from the settings page
- */
- adapter.clearFilteredNumbersCache();
refreshData();
adapter.onResume();
diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
index 63b0c94..53cc4b7 100644
--- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
+++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
@@ -30,6 +30,7 @@
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
+import android.provider.BlockedNumberContract;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -65,7 +66,6 @@
import com.android.dialer.app.calllog.calllogcache.CallLogCache;
import com.android.dialer.app.voicemail.VoicemailPlaybackLayout;
import com.android.dialer.app.voicemail.VoicemailPlaybackPresenter;
-import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.calldetails.CallDetailsEntries;
import com.android.dialer.calldetails.OldCallDetailsActivity;
import com.android.dialer.calllogutils.CallbackActionHelper.CallbackAction;
@@ -189,9 +189,9 @@
*/
public int callType;
/**
- * ID for blocked numbers database. Set when context menu is created, if the number is blocked.
+ * Set when context menu is created, if the number is blocked.
*/
- public Integer blockId;
+ public boolean isBlocked;
/**
* The account for the current call log entry. Cached here as the call back intent is set only
* when the actions ViewStub is inflated.
@@ -346,7 +346,7 @@
displayNumber, number, countryIso, callType, info.sourceType);
} else if (resId == R.id.context_menu_unblock) {
blockReportListener.onUnblock(
- displayNumber, number, countryIso, callType, info.sourceType, isSpam, blockId);
+ displayNumber, number, countryIso, callType, info.sourceType, isSpam);
} else if (resId == R.id.context_menu_report_not_spam) {
blockReportListener.onReportNotSpam(
displayNumber, number, countryIso, callType, info.sourceType);
@@ -629,7 +629,7 @@
callDetailsEntries, buildContact(), canReportCallerId, canSupportAssistedDialing()));
}
- boolean isBlockedOrSpam = blockId != null;
+ boolean isBlockedOrSpam = isBlocked || isSpam;
if (!isBlockedOrSpam && info != null && UriUtils.isEncodedContactUri(info.lookupUri)) {
createNewContactButtonView.setTag(
@@ -871,7 +871,7 @@
if (view.getId() == R.id.unblock_action) {
blockReportListener.onUnblock(
- displayNumber, number, countryIso, callType, info.sourceType, isSpam, blockId);
+ displayNumber, number, countryIso, callType, info.sourceType, isSpam);
return;
}
@@ -968,10 +968,11 @@
String e164Number = PhoneNumberUtils.formatNumberToE164(number, countryIso);
if (!canPlaceCallToNumber
|| isVoicemailNumber
- || !FilteredNumbersUtil.canBlockNumber(context, e164Number, number)) {
+ || !BlockedNumberContract.canCurrentUserBlockNumbers(context)
+ || PhoneNumberUtils.isEmergencyNumber(e164Number)) {
return;
}
- boolean isBlocked = blockId != null;
+
if (isBlocked) {
unblockView.setVisibility(View.VISIBLE);
} else {
@@ -1026,8 +1027,8 @@
boolean canPlaceCallToNumber = PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation);
if (canPlaceCallToNumber
&& !isVoicemailNumber
- && FilteredNumbersUtil.canBlockNumber(context, e164Number, number)) {
- boolean isBlocked = blockId != null;
+ && BlockedNumberContract.canCurrentUserBlockNumbers(context)
+ && !PhoneNumberUtils.isEmergencyNumber(e164Number)) {
if (isBlocked) {
menu.add(
ContextMenu.NONE,
@@ -1082,8 +1083,7 @@
String countryIso,
int callType,
ContactSource.Type contactSourceType,
- boolean isSpam,
- Integer blockId);
+ boolean isSpam);
void onReportNotSpam(
String displayNumber,
diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java
index 659ca3a..9957ae7 100644
--- a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java
+++ b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.net.Uri;
+import android.provider.BlockedNumberContract;
import android.service.notification.StatusBarNotification;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -29,7 +30,6 @@
import com.android.dialer.app.R;
import com.android.dialer.app.calllog.CallLogNotificationsQueryHelper.NewCall;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
-import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutor.Worker;
@@ -37,6 +37,8 @@
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.phonenumbercache.ContactInfo;
import com.android.dialer.telecom.TelecomUtil;
+import com.android.dialer.util.EmergencyCallUtil;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -70,7 +72,7 @@
return;
}
- if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) {
+ if (EmergencyCallUtil.hasRecentEmergencyCall(context)) {
LogUtil.i(
"VisualVoicemailUpdateTask.updateNotification",
"not filtering due to recent emergency call");
@@ -178,7 +180,8 @@
Assert.isWorkerThread();
List<NewCall> result = new ArrayList<>();
for (NewCall newCall : newCalls) {
- if (queryHandler.getBlockedIdSynchronous(newCall.number, newCall.countryIso) != null) {
+ if (BlockedNumberContract.canCurrentUserBlockNumbers(context)
+ && BlockedNumberContract.isBlocked(context, newCall.number)) {
LogUtil.i(
"VisualVoicemailUpdateTask.filterBlockedNumbers",
"found voicemail from blocked number, deleting");
diff --git a/java/com/android/dialer/app/settings/DialerSettingsActivity.java b/java/com/android/dialer/app/settings/DialerSettingsActivity.java
index 84fc83e..5e73253 100644
--- a/java/com/android/dialer/app/settings/DialerSettingsActivity.java
+++ b/java/com/android/dialer/app/settings/DialerSettingsActivity.java
@@ -22,6 +22,7 @@
import android.os.Bundle;
import android.os.UserManager;
import android.preference.PreferenceManager;
+import android.provider.BlockedNumberContract;
import android.provider.Settings;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
@@ -33,7 +34,6 @@
import androidx.annotation.Nullable;
import com.android.dialer.app.R;
-import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.lookup.LookupSettingsFragment;
@@ -131,7 +131,7 @@
phoneAccountSettingsHeader.intent = phoneAccountSettingsIntent;
target.add(phoneAccountSettingsHeader);
}
- if (FilteredNumbersUtil.canCurrentUserOpenBlockSettings(this)) {
+ if (BlockedNumberContract.canCurrentUserBlockNumbers(this)) {
Header blockedCallsHeader = new Header();
blockedCallsHeader.titleRes = R.string.manage_blocked_numbers_label;
blockedCallsHeader.intent = getApplicationContext().getSystemService(TelecomManager.class)
diff --git a/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java b/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java
index 852fd37..e21aa82 100644
--- a/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java
+++ b/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java
@@ -17,35 +17,21 @@
package com.android.dialer.blocking;
import android.content.AsyncQueryHandler;
-import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
-import android.database.DatabaseUtils;
-import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.net.Uri;
+import android.provider.BlockedNumberContract;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.support.v4.os.UserManagerCompat;
-import android.telephony.PhoneNumberUtils;
-import android.text.TextUtils;
-import androidx.annotation.Nullable;
-
-import com.android.dialer.common.Assert;
-import com.android.dialer.common.LogUtil;
-import java.util.Map;
import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
/** TODO(calderwoodra): documentation */
@Deprecated
public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler {
public static final int INVALID_ID = -1;
- // Id used to replace null for blocked id since ConcurrentHashMap doesn't allow null key/value.
- private static final int BLOCKED_NUMBER_CACHE_NULL_ID = -1;
-
- private static final Map<String, Integer> blockedNumberCache = new ConcurrentHashMap<>();
private static final int NO_TOKEN = 0;
private final Context context;
@@ -89,151 +75,6 @@
}
}
- /**
- * Checks if the given number is blocked, calling the given {@link OnCheckBlockedListener} with
- * the id for the blocked number, {@link #INVALID_ID}, or {@code null} based on the result of the
- * check.
- */
- public void isBlockedNumber(
- final OnCheckBlockedListener listener, @Nullable final String number, String countryIso) {
- if (number == null) {
- listener.onCheckComplete(INVALID_ID);
- return;
- }
- if (!FilteredNumbersUtil.canAttemptBlockOperations(context)) {
- listener.onCheckComplete(null);
- return;
- }
- Integer cachedId = blockedNumberCache.get(number);
- if (cachedId != null) {
- if (listener == null) {
- return;
- }
- if (cachedId == BLOCKED_NUMBER_CACHE_NULL_ID) {
- cachedId = null;
- }
- listener.onCheckComplete(cachedId);
- return;
- }
-
- if (!UserManagerCompat.isUserUnlocked(context)) {
- LogUtil.i(
- "FilteredNumberAsyncQueryHandler.isBlockedNumber",
- "Device locked in FBE mode, cannot access blocked number database");
- listener.onCheckComplete(INVALID_ID);
- return;
- }
-
- String e164Number = PhoneNumberUtils.formatNumberToE164(number, countryIso);
- String formattedNumber = FilteredNumbersUtil.getBlockableNumber(e164Number, number);
- if (TextUtils.isEmpty(formattedNumber)) {
- listener.onCheckComplete(INVALID_ID);
- blockedNumberCache.put(number, INVALID_ID);
- return;
- }
-
- startQuery(
- NO_TOKEN,
- new Listener() {
- @Override
- protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- /*
- * In the frameworking blocking, numbers can be blocked in both e164 format
- * and not, resulting in multiple rows being returned for this query. For
- * example, both '16502530000' and '6502530000' can exist at the same time
- * and will be returned by this query.
- */
- if (cursor == null || cursor.getCount() == 0) {
- blockedNumberCache.put(number, BLOCKED_NUMBER_CACHE_NULL_ID);
- listener.onCheckComplete(null);
- return;
- }
- cursor.moveToFirst();
- Integer blockedId = cursor.getInt(cursor.getColumnIndex(BlockedNumbers.COLUMN_ID));
- blockedNumberCache.put(number, blockedId);
- listener.onCheckComplete(blockedId);
- }
- },
- BlockedNumbers.CONTENT_URI,
- new String[] {BlockedNumbers.COLUMN_ID},
- getIsBlockedNumberSelection(e164Number != null) + " = ?",
- new String[] {formattedNumber},
- null);
- }
-
- /**
- * Synchronously check if this number has been blocked.
- *
- * @return blocked id.
- */
- @Nullable
- public Integer getBlockedIdSynchronous(@Nullable String number, String countryIso) {
- Assert.isWorkerThread();
- if (number == null) {
- return null;
- }
- if (!FilteredNumbersUtil.canAttemptBlockOperations(context)) {
- return null;
- }
- Integer cachedId = blockedNumberCache.get(number);
- if (cachedId != null) {
- if (cachedId == BLOCKED_NUMBER_CACHE_NULL_ID) {
- cachedId = null;
- }
- return cachedId;
- }
-
- String e164Number = PhoneNumberUtils.formatNumberToE164(number, countryIso);
- String formattedNumber = FilteredNumbersUtil.getBlockableNumber(e164Number, number);
- if (TextUtils.isEmpty(formattedNumber)) {
- return null;
- }
-
- try (Cursor cursor =
- context
- .getContentResolver()
- .query(
- BlockedNumbers.CONTENT_URI,
- new String[] {BlockedNumbers.COLUMN_ID},
- getIsBlockedNumberSelection(e164Number != null) + " = ?",
- new String[] {formattedNumber},
- null)) {
- /*
- * In the frameworking blocking, numbers can be blocked in both e164 format
- * and not, resulting in multiple rows being returned for this query. For
- * example, both '16502530000' and '6502530000' can exist at the same time
- * and will be returned by this query.
- */
- if (cursor == null || cursor.getCount() == 0) {
- blockedNumberCache.put(number, BLOCKED_NUMBER_CACHE_NULL_ID);
- return null;
- }
- cursor.moveToFirst();
- int blockedId = cursor.getInt(cursor.getColumnIndex(BlockedNumbers.COLUMN_ID));
- blockedNumberCache.put(number, blockedId);
- return blockedId;
- } catch (SecurityException e) {
- LogUtil.e("FilteredNumberAsyncQueryHandler.getBlockedIdSynchronous", null, e);
- return null;
- }
- }
-
- public void clearCache() {
- blockedNumberCache.clear();
- }
-
- /*
- * TODO(maxwelb): a bug, non-e164 numbers can be blocked in the new form of blocking. As a
- * temporary workaround, determine which column of the database to query based on whether the
- * number is e164 or not.
- */
- private String getIsBlockedNumberSelection(boolean isE164Number) {
- if (!isE164Number) {
- return BlockedNumbers.COLUMN_ORIGINAL_NUMBER;
- }
- return BlockedNumbers.COLUMN_E164_NUMBER;
- }
-
/** Add a number manually blocked by the user. */
public void blockNumber(final OnBlockNumberListener listener, String number) {
ContentValues contentValues = new ContentValues();
@@ -246,8 +87,7 @@
* performing the 'undo' action after unblocking.
*/
public void blockNumber(final OnBlockNumberListener listener, ContentValues values) {
- blockedNumberCache.clear();
- if (!FilteredNumbersUtil.canAttemptBlockOperations(context)) {
+ if (!BlockedNumberContract.canCurrentUserBlockNumbers(context)) {
if (listener != null) {
listener.onBlockComplete(null);
}
@@ -267,83 +107,6 @@
values);
}
- /**
- * Unblocks the number with the given id.
- *
- * @param listener (optional) The {@link OnUnblockNumberListener} called after the number is
- * unblocked.
- * @param id The id of the number to unblock.
- */
- public void unblock(@Nullable final OnUnblockNumberListener listener, Integer id) {
- if (id == null) {
- throw new IllegalArgumentException("Null id passed into unblock");
- }
- unblock(listener, ContentUris.withAppendedId(BlockedNumbers.CONTENT_URI, id));
- }
-
- /**
- * Removes row from database.
- *
- * @param listener (optional) The {@link OnUnblockNumberListener} called after the number is
- * unblocked.
- * @param uri The uri of row to remove, from {@link FilteredNumberAsyncQueryHandler#blockNumber}.
- */
- public void unblock(@Nullable final OnUnblockNumberListener listener, final Uri uri) {
- blockedNumberCache.clear();
- if (!FilteredNumbersUtil.canAttemptBlockOperations(context)) {
- if (listener != null) {
- listener.onUnblockComplete(0, null);
- }
- return;
- }
- startQuery(
- NO_TOKEN,
- new Listener() {
- @Override
- public void onQueryComplete(int token, Object cookie, Cursor cursor) {
- int rowsReturned = cursor == null ? 0 : cursor.getCount();
- if (rowsReturned != 1) {
- throw new SQLiteDatabaseCorruptException(
- "Returned " + rowsReturned + " rows for uri " + uri + "where 1 expected.");
- }
- cursor.moveToFirst();
- final ContentValues values = new ContentValues();
- DatabaseUtils.cursorRowToContentValues(cursor, values);
- values.remove(BlockedNumbers.COLUMN_ID);
-
- startDelete(
- NO_TOKEN,
- new Listener() {
- @Override
- public void onDeleteComplete(int token, Object cookie, int result) {
- if (listener != null) {
- listener.onUnblockComplete(result, values);
- }
- }
- },
- uri,
- null,
- null);
- }
- },
- uri,
- null,
- null,
- null,
- null);
- }
-
- /** TODO(calderwoodra): documentation */
- public interface OnCheckBlockedListener {
-
- /**
- * Invoked after querying if a number is blocked.
- *
- * @param id The ID of the row if blocked, null otherwise.
- */
- void onCheckComplete(Integer id);
- }
-
/** TODO(calderwoodra): documentation */
public interface OnBlockNumberListener {
@@ -355,18 +118,6 @@
void onBlockComplete(Uri uri);
}
- /** TODO(calderwoodra): documentation */
- public interface OnUnblockNumberListener {
-
- /**
- * Invoked after removing a blocked number
- *
- * @param rows The number of rows affected (expected value 1).
- * @param values The deleted data (used for restoration).
- */
- void onUnblockComplete(int rows, ContentValues values);
- }
-
/** Methods for FilteredNumberAsyncQueryHandler result returns. */
private abstract static class Listener {
diff --git a/java/com/android/dialer/blocking/FilteredNumbersUtil.java b/java/com/android/dialer/blocking/FilteredNumbersUtil.java
deleted file mode 100644
index d0cbf04..0000000
--- a/java/com/android/dialer/blocking/FilteredNumbersUtil.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.dialer.blocking;
-
-import android.content.Context;
-import android.provider.BlockedNumberContract;
-import android.provider.Settings;
-import android.telephony.PhoneNumberUtils;
-import android.text.TextUtils;
-
-import androidx.annotation.Nullable;
-
-import com.android.dialer.common.LogUtil;
-import com.android.dialer.storage.StorageComponent;
-import com.android.dialer.telecom.TelecomUtil;
-import java.util.concurrent.TimeUnit;
-
-/** Utility to help with tasks related to filtered numbers. */
-@Deprecated
-public class FilteredNumbersUtil {
-
- // 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";
- // 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.
- protected static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
- "notified_call_blocking_disabled_by_emergency_call";
- // Disable incoming call blocking if there was a call within the past 2 days.
- static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = TimeUnit.DAYS.toMillis(2);
-
- /**
- * Used for testing to specify the custom threshold value, in milliseconds for whether an
- * emergency call is "recent". The default value will be used if this custom threshold is less
- * than zero. For example, to set this threshold to 60 seconds:
- *
- * <p>adb shell settings put system dialer_emergency_call_threshold_ms 60000
- */
- private static final String RECENT_EMERGENCY_CALL_THRESHOLD_SETTINGS_KEY =
- "dialer_emergency_call_threshold_ms";
-
- public static long getLastEmergencyCallTimeMillis(Context context) {
- return StorageComponent.get(context)
- .unencryptedSharedPrefs()
- .getLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, 0);
- }
-
- public static boolean hasRecentEmergencyCall(Context context) {
- if (context == null) {
- return false;
- }
-
- Long lastEmergencyCallTime = getLastEmergencyCallTimeMillis(context);
- if (lastEmergencyCallTime == 0) {
- return false;
- }
-
- return (System.currentTimeMillis() - lastEmergencyCallTime)
- < getRecentEmergencyCallThresholdMs(context);
- }
-
- public static void recordLastEmergencyCallTime(Context context) {
- if (context == null) {
- return;
- }
-
- StorageComponent.get(context)
- .unencryptedSharedPrefs()
- .edit()
- .putLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, System.currentTimeMillis())
- .putBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)
- .apply();
- }
-
- /**
- * @param e164Number The e164 formatted version of the number, or {@code null} if such a format
- * doesn't exist.
- * @param number The number to attempt blocking.
- * @return {@code true} if the number can be blocked, {@code false} otherwise.
- */
- public static boolean canBlockNumber(Context context, String e164Number, String number) {
- String blockableNumber = getBlockableNumber(e164Number, number);
- return canAttemptBlockOperations(context) && !TextUtils.isEmpty(blockableNumber)
- && !PhoneNumberUtils.isEmergencyNumber(blockableNumber);
- }
-
- /**
- * @param e164Number The e164 formatted version of the number, or {@code null} if such a format
- * doesn't exist..
- * @param number The number to attempt blocking.
- * @return The version of the given number that can be blocked with the current blocking solution.
- */
- @Nullable
- public static String getBlockableNumber(@Nullable String e164Number, String number) {
- return TextUtils.isEmpty(e164Number) ? number : e164Number;
- }
-
- private static long getRecentEmergencyCallThresholdMs(Context context) {
- if (LogUtil.isVerboseEnabled()) {
- long thresholdMs =
- Settings.System.getLong(
- context.getContentResolver(), RECENT_EMERGENCY_CALL_THRESHOLD_SETTINGS_KEY, 0);
- return thresholdMs > 0 ? thresholdMs : RECENT_EMERGENCY_CALL_THRESHOLD_MS;
- } else {
- return RECENT_EMERGENCY_CALL_THRESHOLD_MS;
- }
- }
-
- /**
- * Method used to determine if block operations are possible.
- *
- * @param context The {@link Context}.
- * @return {@code true} if the app and user can block numbers, {@code false} otherwise.
- */
- public static boolean canAttemptBlockOperations(Context context) {
- // Great Wall blocking, must be primary user and the default or system dialer
- // TODO(maxwelb): check that we're the system Dialer
- return TelecomUtil.isDefaultDialer(context)
- && safeBlockedNumbersContractCanCurrentUserBlockNumbers(context);
- }
-
- /**
- * Used to determine if the call blocking settings can be opened.
- *
- * @param context The {@link Context}.
- * @return {@code true} if the current user can open the call blocking settings, {@code false}
- * otherwise.
- */
- public static boolean canCurrentUserOpenBlockSettings(Context context) {
- // BlockedNumberContract blocking, verify through Contract API
- return TelecomUtil.isDefaultDialer(context)
- && safeBlockedNumbersContractCanCurrentUserBlockNumbers(context);
- }
-
- /**
- * Calls {@link BlockedNumberContract#canCurrentUserBlockNumbers(Context)} in such a way that it
- * never throws an exception. While on the CryptKeeper screen, the BlockedNumberContract isn't
- * available, using this method ensures that the Dialer doesn't crash when on that screen.
- *
- * @param context The {@link Context}.
- * @return the result of BlockedNumberContract#canCurrentUserBlockNumbers, or {@code false} if an
- * exception was thrown.
- */
- private static boolean safeBlockedNumbersContractCanCurrentUserBlockNumbers(Context context) {
- try {
- return BlockedNumberContract.canCurrentUserBlockNumbers(context);
- } catch (Exception e) {
- LogUtil.e(
- "FilteredNumberCompat.safeBlockedNumbersContractCanCurrentUserBlockNumbers",
- "Exception while querying BlockedNumberContract",
- e);
- return false;
- }
- }
-}
diff --git a/java/com/android/dialer/util/EmergencyCallUtil.java b/java/com/android/dialer/util/EmergencyCallUtil.java
new file mode 100644
index 0000000..cbcddee
--- /dev/null
+++ b/java/com/android/dialer/util/EmergencyCallUtil.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.dialer.util;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.dialer.common.LogUtil;
+import com.android.dialer.storage.StorageComponent;
+
+import java.util.concurrent.TimeUnit;
+
+/** Utility to help with tasks related to emergency calls. */
+public class EmergencyCallUtil {
+
+ // 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";
+ // 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.
+ protected static final String NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY =
+ "notified_call_blocking_disabled_by_emergency_call";
+ // Disable incoming call blocking if there was a call within the past 2 days.
+ static final long RECENT_EMERGENCY_CALL_THRESHOLD_MS = TimeUnit.DAYS.toMillis(2);
+
+ /**
+ * Used for testing to specify the custom threshold value, in milliseconds for whether an
+ * emergency call is "recent". The default value will be used if this custom threshold is less
+ * than zero. For example, to set this threshold to 60 seconds:
+ *
+ * <p>adb shell settings put system dialer_emergency_call_threshold_ms 60000
+ */
+ private static final String RECENT_EMERGENCY_CALL_THRESHOLD_SETTINGS_KEY =
+ "dialer_emergency_call_threshold_ms";
+
+ public static long getLastEmergencyCallTimeMillis(Context context) {
+ return StorageComponent.get(context)
+ .unencryptedSharedPrefs()
+ .getLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, 0);
+ }
+
+ public static boolean hasRecentEmergencyCall(Context context) {
+ if (context == null) {
+ return false;
+ }
+
+ Long lastEmergencyCallTime = getLastEmergencyCallTimeMillis(context);
+ if (lastEmergencyCallTime == 0) {
+ return false;
+ }
+
+ return (System.currentTimeMillis() - lastEmergencyCallTime)
+ < getRecentEmergencyCallThresholdMs(context);
+ }
+
+ public static void recordLastEmergencyCallTime(Context context) {
+ if (context == null) {
+ return;
+ }
+
+ StorageComponent.get(context)
+ .unencryptedSharedPrefs()
+ .edit()
+ .putLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, System.currentTimeMillis())
+ .putBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)
+ .apply();
+ }
+
+ private static long getRecentEmergencyCallThresholdMs(Context context) {
+ if (LogUtil.isVerboseEnabled()) {
+ long thresholdMs =
+ Settings.System.getLong(
+ context.getContentResolver(), RECENT_EMERGENCY_CALL_THRESHOLD_SETTINGS_KEY, 0);
+ return thresholdMs > 0 ? thresholdMs : RECENT_EMERGENCY_CALL_THRESHOLD_MS;
+ } else {
+ return RECENT_EMERGENCY_CALL_THRESHOLD_MS;
+ }
+ }
+}
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index 5ef725f..9e0dd49 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -44,14 +44,12 @@
import com.android.dialer.CallConfiguration;
import com.android.dialer.Mode;
import com.android.dialer.R;
-import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
-import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
-import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.postcall.PostCall;
import com.android.dialer.telecom.TelecomUtil;
+import com.android.dialer.util.EmergencyCallUtil;
import com.android.dialer.util.TouchPointManager;
import com.android.incallui.InCallOrientationEventListener.ScreenOrientation;
import com.android.incallui.answerproximitysensor.PseudoScreenState;
@@ -69,7 +67,7 @@
import com.android.incallui.videosurface.bindings.VideoSurfaceBindings;
import com.android.incallui.videosurface.protocol.VideoSurfaceTexture;
import com.android.incallui.videotech.utils.VideoUtils;
-import com.google.protobuf.InvalidProtocolBufferException;
+
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@@ -116,17 +114,6 @@
private InCallDndHandler dndHandler;
private ContactInfoCache contactInfoCache;
private Context context;
- private final OnCheckBlockedListener onCheckBlockedListener =
- new OnCheckBlockedListener() {
- @Override
- public void onCheckComplete(final Integer id) {
- if (id != null && id != FilteredNumberAsyncQueryHandler.INVALID_ID) {
- // Silence the ringer now to prevent ringing and vibration before the call is
- // terminated when Telecom attempts to add it.
- TelecomUtil.silenceRinger(context);
- }
- }
- };
private CallList callList;
private ExternalCallList externalCallList;
private InCallActivity inCallActivity;
@@ -200,7 +187,7 @@
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
- if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) {
+ if (EmergencyCallUtil.hasRecentEmergencyCall(context)) {
return;
}
// Check if the number is blocked, to silence the ringer.
@@ -814,7 +801,7 @@
}
if (call.isEmergencyCall()) {
- FilteredNumbersUtil.recordLastEmergencyCallTime(context);
+ EmergencyCallUtil.recordLastEmergencyCallTime(context);
}
if (!callList.hasLiveCall()
diff --git a/java/com/android/incallui/call/CallList.java b/java/com/android/incallui/call/CallList.java
index 5dceda8..fb03a48 100644
--- a/java/com/android/incallui/call/CallList.java
+++ b/java/com/android/incallui/call/CallList.java
@@ -20,6 +20,7 @@
import android.os.Handler;
import android.os.Message;
import android.os.Trace;
+import android.provider.BlockedNumberContract;
import android.telecom.Call;
import android.telecom.DisconnectCause;
import android.telecom.PhoneAccount;
@@ -116,21 +117,11 @@
Trace.endSection();
Trace.beginSection("checkBlock");
- FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler =
- new FilteredNumberAsyncQueryHandler(context);
- filteredNumberAsyncQueryHandler.isBlockedNumber(
- new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() {
- @Override
- public void onCheckComplete(Integer id) {
- if (id != null && id != FilteredNumberAsyncQueryHandler.INVALID_ID) {
- call.setBlockedStatus(true);
- // No need to update UI since it's only used for logging.
- }
- }
- },
- call.getNumber(),
- call.getCountryIso());
+ if (BlockedNumberContract.canCurrentUserBlockNumbers(context) &&
+ BlockedNumberContract.isBlocked(context, call.getNumber())) {
+ call.setBlockedStatus(true);
+ }
Trace.endSection();
if (call.getState() == DialerCallState.INCOMING
diff --git a/java/com/android/incallui/spam/SpamCallListListener.java b/java/com/android/incallui/spam/SpamCallListListener.java
index d976cc3..96eac1b 100644
--- a/java/com/android/incallui/spam/SpamCallListListener.java
+++ b/java/com/android/incallui/spam/SpamCallListListener.java
@@ -28,12 +28,10 @@
import androidx.annotation.Nullable;
import com.android.dialer.R;
-import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.DialerExecutor.Worker;
import com.android.dialer.common.concurrent.DialerExecutorFactory;
-import com.android.dialer.location.GeoUtil;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
import com.android.incallui.call.CallList;
@@ -143,23 +141,5 @@
public void onInternationalCallOnWifi(@NonNull DialerCall call) {}
@Override
- public void onDisconnect(DialerCall call) {
- if (!shouldShowAfterCallNotification(call)) {
- return;
- }
- String e164Number =
- PhoneNumberUtils.formatNumberToE164(
- call.getNumber(), GeoUtil.getCurrentCountryIso(context));
- if (!FilteredNumbersUtil.canBlockNumber(context, e164Number, call.getNumber())) {
- return;
- }
- if (e164Number == null) {
- return;
- }
- }
-
- /** Determines if the after call notification should be shown for the specified call. */
- private boolean shouldShowAfterCallNotification(DialerCall call) {
- return false;
- }
+ public void onDisconnect(DialerCall call) {}
}