diff options
Diffstat (limited to 'src/com/android/dialer')
6 files changed, 116 insertions, 32 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 6c8d7708a..42bee1edf 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -59,7 +59,6 @@ import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.filterednumber.BlockNumberDialogFragment; import com.android.dialer.filterednumber.FilteredNumbersUtil; -import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; import com.android.dialer.util.DialerUtils; @@ -156,7 +155,8 @@ public class CallDetailActivity extends AppCompatActivity PhoneNumberUtil.canPlaceCallsTo(mNumber, mDetails.numberPresentation); mCallButton.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); mCopyNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); - mBlockNumberActionItem.setVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); + + updateBlockActionItemVisibility(canPlaceCallsTo ? View.VISIBLE : View.GONE); final boolean isSipNumber = PhoneNumberUtil.isSipNumber(mNumber); final boolean isVoicemailNumber = @@ -277,7 +277,9 @@ public class CallDetailActivity extends AppCompatActivity } }); + mBlockNumberActionItem = (TextView) findViewById(R.id.call_detail_action_block); + updateBlockActionItemVisibility(View.VISIBLE); mBlockNumberActionItem.setOnClickListener(this); mEditBeforeCallActionItem = findViewById(R.id.call_detail_action_edit_before_call); mEditBeforeCallActionItem.setOnClickListener(this); @@ -292,6 +294,13 @@ public class CallDetailActivity extends AppCompatActivity } } + private void updateBlockActionItemVisibility(int visibility) { + if (!FilteredNumberCompat.canAttemptBlockOperations(mContext)) { + visibility = View.GONE; + } + mBlockNumberActionItem.setVisibility(visibility); + } + @Override public void onResume() { super.onResume(); @@ -468,8 +477,6 @@ public class CallDetailActivity extends AppCompatActivity mBlockNumberActionItem.setCompoundDrawablesRelativeWithIntrinsicBounds( R.drawable.ic_call_detail_unblock, 0, 0, 0); } - - mBlockNumberActionItem.setVisibility(View.VISIBLE); } private void closeSystemDialogs() { diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 750914bdf..baf2e1ab5 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -55,7 +55,6 @@ import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.filterednumber.BlockNumberDialogFragment; import com.android.dialer.filterednumber.FilteredNumbersUtil; -import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; import com.android.dialer.service.ExtendedBlockingButtonRenderer; @@ -346,7 +345,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder .setOnMenuItemClickListener(this); } - if (FilteredNumbersUtil.canBlockNumber(mContext, number, countryIso)) { + if (FilteredNumberCompat.canAttemptBlockOperations(mContext) + && FilteredNumbersUtil.canBlockNumber(mContext, number, countryIso)) { mFilteredNumberAsyncQueryHandler.isBlockedNumber( new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() { @Override diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java index c6c714b27..91563dc0d 100644 --- a/src/com/android/dialer/compat/FilteredNumberCompat.java +++ b/src/com/android/dialer/compat/FilteredNumberCompat.java @@ -25,15 +25,19 @@ import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.UserManager; 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; @@ -44,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; @@ -256,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"); @@ -280,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. * @@ -293,4 +325,39 @@ public class FilteredNumberCompat { } return new Intent(context, BlockedNumbersSettingsActivity.class); } + + /** + * 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) { + if (!CompatUtils.isNCompatible()) { + // Dialer blocking, must be primary user + return UserManagerCompat.isSystemUser( + (UserManager) context.getSystemService(Context.USER_SERVICE)); + } + + // Great Wall blocking, must be primary user and the default or system dialer + // TODO(maxwelb): check that we're the default or system Dialer + return BlockedNumbersSdkCompat.canCurrentUserBlockNumbers(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) { + if (!CompatUtils.isNCompatible()) { + // Dialer blocking, must be primary user + return UserManagerCompat.isSystemUser( + (UserManager) context.getSystemService(Context.USER_SERVICE)); + } + // BlockedNumberContract blocking, verify through Contract API + return BlockedNumbersSdkCompat.canCurrentUserBlockNumbers(context); + } } diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java index 7af1a1339..52ef49ac0 100644 --- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java +++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java @@ -158,7 +158,13 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { new Listener() { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { - if (cursor == null || cursor.getCount() != 1) { + /* + * 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) { listener.onCheckComplete(null); return; } diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java index e3870ded9..498b10a45 100644 --- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java +++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java @@ -33,6 +33,7 @@ import android.widget.Toast; import com.android.contacts.common.testing.NeededForTesting; import com.android.dialer.R; +import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumber; @@ -298,6 +299,10 @@ public class FilteredNumbersUtil { } public static void maybeNotifyCallBlockingDisabled(final Context context) { + // The Dialer is not responsible for this notification after migrating + if (FilteredNumberCompat.useNewFiltering()) { + return; + } // Skip if the user has already received a notification for the most recent emergency call. if (PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(NOTIFIED_CALL_BLOCKING_DISABLED_BY_EMERGENCY_CALL_PREF_KEY, false)) { diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index bbcbd49fc..fc689d037 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -94,22 +94,21 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { phoneAccountSettingsHeader.intent = phoneAccountSettingsIntent; target.add(phoneAccountSettingsHeader); } - if (isPrimaryUser) { + if (FilteredNumberCompat.canCurrentUserOpenBlockSettings(this)) { Header blockedCallsHeader = new Header(); blockedCallsHeader.titleRes = R.string.manage_blocked_numbers_label; blockedCallsHeader.intent = FilteredNumberCompat.createManageBlockedNumbersIntent(this); target.add(blockedCallsHeader); - - if (TelephonyManagerCompat.isTtyModeSupported(telephonyManager) - || TelephonyManagerCompat - .isHearingAidCompatibilitySupported(telephonyManager)) { - Header accessibilitySettingsHeader = new Header(); - Intent accessibilitySettingsIntent = - new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); - accessibilitySettingsHeader.titleRes = R.string.accessibility_settings_title; - accessibilitySettingsHeader.intent = accessibilitySettingsIntent; - target.add(accessibilitySettingsHeader); - } + } + if (isPrimaryUser + && (TelephonyManagerCompat.isTtyModeSupported(telephonyManager) + || TelephonyManagerCompat.isHearingAidCompatibilitySupported(telephonyManager))) { + Header accessibilitySettingsHeader = new Header(); + Intent accessibilitySettingsIntent = + new Intent(TelecomManager.ACTION_SHOW_CALL_ACCESSIBILITY_SETTINGS); + accessibilitySettingsHeader.titleRes = R.string.accessibility_settings_title; + accessibilitySettingsHeader.intent = accessibilitySettingsIntent; + target.add(accessibilitySettingsHeader); } } |