diff options
Diffstat (limited to 'java/com/android/dialer/blocking')
4 files changed, 26 insertions, 63 deletions
diff --git a/java/com/android/dialer/blocking/BlockedNumbersAutoMigrator.java b/java/com/android/dialer/blocking/BlockedNumbersAutoMigrator.java index 3cc42207d..6e9fe1315 100644 --- a/java/com/android/dialer/blocking/BlockedNumbersAutoMigrator.java +++ b/java/com/android/dialer/blocking/BlockedNumbersAutoMigrator.java @@ -21,6 +21,7 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.os.UserManagerCompat; import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; @@ -100,6 +101,10 @@ public class BlockedNumbersAutoMigrator { @Nullable @Override public Boolean doInBackground(@Nullable Void input) { + if (!UserManagerCompat.isUserUnlocked(appContext)) { + LogUtil.i("BlockedNumbersAutoMigrator", "not attempting auto-migrate: device is locked"); + return false; + } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext); diff --git a/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java b/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java index bd4156846..fa74850ba 100644 --- a/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java +++ b/java/com/android/dialer/blocking/FilteredNumberAsyncQueryHandler.java @@ -137,14 +137,6 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { return; } - String e164Number = PhoneNumberUtils.formatNumberToE164(number, countryIso); - String formattedNumber = FilteredNumbersUtil.getBlockableNumber(context, e164Number, number); - if (TextUtils.isEmpty(formattedNumber)) { - listener.onCheckComplete(INVALID_ID); - blockedNumberCache.put(number, INVALID_ID); - return; - } - if (!UserManagerCompat.isUserUnlocked(context)) { LogUtil.i( "FilteredNumberAsyncQueryHandler.isBlockedNumber", @@ -153,6 +145,14 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { return; } + String e164Number = PhoneNumberUtils.formatNumberToE164(number, countryIso); + String formattedNumber = FilteredNumbersUtil.getBlockableNumber(context, e164Number, number); + if (TextUtils.isEmpty(formattedNumber)) { + listener.onCheckComplete(INVALID_ID); + blockedNumberCache.put(number, INVALID_ID); + return; + } + startQuery( NO_TOKEN, new Listener() { @@ -201,7 +201,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { */ @TargetApi(VERSION_CODES.M) @Nullable - public Integer getBlockedIdSynchronousForCalllogOnly(@Nullable String number, String countryIso) { + public Integer getBlockedIdSynchronous(@Nullable String number, String countryIso) { Assert.isWorkerThread(); if (number == null) { return null; @@ -251,7 +251,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { blockedNumberCache.put(number, blockedId); return blockedId; } catch (SecurityException e) { - LogUtil.e("FilteredNumberAsyncQueryHandler.getBlockedIdSynchronousForCalllogOnly", null, e); + LogUtil.e("FilteredNumberAsyncQueryHandler.getBlockedIdSynchronous", null, e); return null; } } diff --git a/java/com/android/dialer/blocking/FilteredNumberProvider.java b/java/com/android/dialer/blocking/FilteredNumberProvider.java index 5d369038c..8ed781e73 100644 --- a/java/com/android/dialer/blocking/FilteredNumberProvider.java +++ b/java/com/android/dialer/blocking/FilteredNumberProvider.java @@ -26,12 +26,12 @@ import android.database.sqlite.SQLiteQueryBuilder; import android.net.Uri; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; -import android.util.Log; -import com.android.contacts.common.GeoUtil; +import com.android.dialer.common.LogUtil; import com.android.dialer.database.Database; import com.android.dialer.database.DialerDatabaseHelper; import com.android.dialer.database.FilteredNumberContract; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; +import com.android.dialer.location.GeoUtil; /** Filtered number content provider. */ public class FilteredNumberProvider extends ContentProvider { @@ -39,7 +39,6 @@ public class FilteredNumberProvider extends ContentProvider { private static final int FILTERED_NUMBERS_TABLE = 1; private static final int FILTERED_NUMBERS_TABLE_ID = 2; private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); - private static final String TAG = FilteredNumberProvider.class.getSimpleName(); private DialerDatabaseHelper mDialerDatabaseHelper; @Override @@ -80,7 +79,7 @@ public class FilteredNumberProvider extends ContentProvider { c.setNotificationUri( getContext().getContentResolver(), FilteredNumberContract.FilteredNumber.CONTENT_URI); } else { - Log.d(TAG, "CURSOR WAS NULL"); + LogUtil.d("FilteredNumberProvider.query", "CURSOR WAS NULL"); } return c; } diff --git a/java/com/android/dialer/blocking/FilteredNumbersUtil.java b/java/com/android/dialer/blocking/FilteredNumbersUtil.java index cbef73ca5..3c001a2c2 100644 --- a/java/com/android/dialer/blocking/FilteredNumbersUtil.java +++ b/java/com/android/dialer/blocking/FilteredNumbersUtil.java @@ -27,19 +27,18 @@ import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts; import android.provider.Settings; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.widget.Toast; import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; import com.android.dialer.common.LogUtil; -import com.android.dialer.database.FilteredNumberContract.FilteredNumber; -import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.notification.NotificationChannelManager; import com.android.dialer.notification.NotificationChannelManager.Channel; +import com.android.dialer.util.DialerUtils; import com.android.dialer.util.PermissionsUtil; -import java.util.concurrent.TimeUnit; /** Utility to help with tasks related to filtered numbers. */ public class FilteredNumbersUtil { @@ -47,8 +46,9 @@ public class FilteredNumbersUtil { public static final String CALL_BLOCKING_NOTIFICATION_TAG = "call_blocking"; public static final int CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_NOTIFICATION_ID = R.id.notification_call_blocking_disabled_by_emergency_call; - // Pref key for storing the time of end of the last emergency call in milliseconds after epoch. - protected static final String LAST_EMERGENCY_CALL_MS_PREF_KEY = "last_emergency_call_ms"; + // Pref key for storing the time of end of the last emergency call in milliseconds after epoch.\ + @VisibleForTesting + public 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 = @@ -73,7 +73,7 @@ public class FilteredNumbersUtil { new AsyncTask<Object, Void, Boolean>() { @Override public Boolean doInBackground(Object... params) { - if (context == null || !PermissionsUtil.hasContactsPermissions(context)) { + if (context == null || !PermissionsUtil.hasContactsReadPermissions(context)) { return false; } @@ -186,49 +186,8 @@ public class FilteredNumbersUtil { task.execute(); } - /** - * WARNING: This method should NOT be executed on the UI thread. Use {@code - * FilteredNumberAsyncQueryHandler} to asynchronously check if a number is blocked. - */ - public static boolean shouldBlockVoicemail( - Context context, String number, String countryIso, long voicemailDateMs) { - final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); - if (TextUtils.isEmpty(normalizedNumber)) { - return false; - } - - if (hasRecentEmergencyCall(context)) { - return false; - } - - final Cursor cursor = - context - .getContentResolver() - .query( - FilteredNumber.CONTENT_URI, - new String[] {FilteredNumberColumns.CREATION_TIME}, - FilteredNumberColumns.NORMALIZED_NUMBER + "=?", - new String[] {normalizedNumber}, - null); - 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(); - } - } - public static long getLastEmergencyCallTimeMillis(Context context) { - return PreferenceManager.getDefaultSharedPreferences(context) + return DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context) .getLong(LAST_EMERGENCY_CALL_MS_PREF_KEY, 0); } @@ -292,7 +251,7 @@ public class FilteredNumbersUtil { context.getString(R.string.call_blocking_disabled_notification_text)) .setAutoCancel(true); - NotificationChannelManager.applyChannel(builder, context, Channel.MISC, null); + NotificationChannelManager.applyChannel(builder, context, Channel.DEFAULT, null); builder.setContentIntent( PendingIntent.getActivity( context, |