diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-22 02:00:45 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-03-22 02:00:45 +0000 |
commit | ecacd03b1dc86afadecdf99ef3a11a09e4a38888 (patch) | |
tree | 1cb9a858ac89b8519916155c4f3cefe2bc66c786 /src | |
parent | 25b094b0473bb52238d7d45d4ba69b0d9949121c (diff) | |
parent | ac6cd58c8642d22e47a6d4b30295137a61177e85 (diff) |
Checking for blocked number after migrating
am: ac6cd58
* commit 'ac6cd58c8642d22e47a6d4b30295137a61177e85':
Checking for blocked number after migrating
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/compat/FilteredNumberCompat.java | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java index 532cec5ac..91563dc0d 100644 --- a/src/com/android/dialer/compat/FilteredNumberCompat.java +++ b/src/com/android/dialer/compat/FilteredNumberCompat.java @@ -30,11 +30,14 @@ import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; +import android.util.Log; import com.android.contacts.common.compat.CompatUtils; import com.android.contacts.common.compat.TelecomManagerUtil; import com.android.contacts.common.testing.NeededForTesting; import com.android.dialer.DialerApplication; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumber; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; @@ -45,7 +48,6 @@ import com.android.dialer.filterednumber.BlockedNumbersMigrator; import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity; import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment; import com.android.dialerbind.ObjectFactory; -import com.android.incallui.Log; import java.util.ArrayList; import java.util.List; @@ -257,18 +259,10 @@ public class FilteredNumberCompat { if (shouldShowMigrationDialog(blockId == null)) { Log.i(TAG, "showBlockNumberDialogFlow - showing migration dialog"); MigrateBlockedNumbersDialogFragment - .newInstance(new BlockedNumbersMigrator(contentResolver), - new BlockedNumbersMigrator.Listener() { - @Override - public void onComplete() { - Log.i(TAG, "showBlockNumberDialogFlow - listener showing block " - + "number dialog"); - BlockNumberDialogFragment - .show(null, number, countryIso, displayNumber, - parentViewId, - fragmentManager, callback); - } - }).show(fragmentManager, "MigrateBlockedNumbers"); + .newInstance(new BlockedNumbersMigrator(contentResolver), newMigrationListener( + DialerApplication.getContext().getContentResolver(), number, countryIso, + displayNumber, parentViewId, fragmentManager, callback)) + .show(fragmentManager, "MigrateBlockedNumbers"); return; } Log.i(TAG, "showBlockNumberDialogFlow - showing block number dialog"); @@ -281,6 +275,43 @@ public class FilteredNumberCompat { return isBlocking && canUseNewFiltering() && !hasMigratedToNewBlocking(); } + private static BlockedNumbersMigrator.Listener newMigrationListener( + final ContentResolver contentResolver, final String number, final String countryIso, + final String displayNumber, final Integer parentViewId, + final FragmentManager fragmentManager, @Nullable final Callback callback) { + return new BlockedNumbersMigrator.Listener() { + @Override + public void onComplete() { + Log.i(TAG, "showBlockNumberDialogFlow - listener showing block number dialog"); + if (!hasMigratedToNewBlocking()) { + Log.i(TAG, "showBlockNumberDialogFlow - migration failed"); + return; + } + /* + * Edge case to cover here: if the user initiated the migration workflow with a + * number that's already blocked in the framework, don't show the block number + * dialog. Doing so would allow them to block the same number twice, causing a + * crash. + */ + new FilteredNumberAsyncQueryHandler(contentResolver).isBlockedNumber( + new OnCheckBlockedListener() { + @Override + public void onCheckComplete(Integer id) { + if (id != null) { + Log.i(TAG, + "showBlockNumberDialogFlow - number already blocked"); + return; + } + Log.i(TAG, "showBlockNumberDialogFlow - need to block number"); + BlockNumberDialogFragment + .show(null, number, countryIso, displayNumber, parentViewId, + fragmentManager, callback); + } + }, number, countryIso); + } + }; + } + /** * Creates the {@link Intent} which opens the blocked numbers management interface. * |