diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-21 14:37:47 -0700 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-03-21 17:33:55 -0700 |
commit | ac6cd58c8642d22e47a6d4b30295137a61177e85 (patch) | |
tree | ccee0d6e755ca88e3b73b599d7bc219a3668a63f /src/com/android | |
parent | c98a56336fd49a8c5ea2834a141627d3cf0d8d6d (diff) |
Checking for blocked number after migrating
+ There's an edge case crash in the Dialer when initiating the
migration workflow. If the user has blocked a number in the framework
prior to migrating the Dialer and then attempts to block that number
again in the Dialer, the migration workflow starts, completes, and
then the app crashes. This is because prior to migrating, the Dialer
doesn't know that the number is blocked in the framework, allowing it
to block the same number twice.
+ Since this case is specific to the situation where an already
blocked number initiates migration, this CL fixes the problem by
checking if the number is blocked in the framework, prior to blocking
it after the migration.
Change-Id: I31c8978afb871f364e63cab5cc6da3e5fd106b29
Fixes: 27720157
Diffstat (limited to 'src/com/android')
-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. * |