summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-03-15 21:52:27 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-03-15 21:52:27 +0000
commit24fdf0da0966a7a4108db7fc7e23f6c5a3b651a3 (patch)
treed2c8ef2f344c649bf4f57aca519117341af6c34b
parent3cd1ce6c8801c338f45dad8688e2f742f910382d (diff)
parent60d449f45f52c22d7f7e669760457b717352f8de (diff)
Updating settings to use system blocked numbers ui
am: 60d449f45f * commit '60d449f45f52c22d7f7e669760457b717352f8de': Updating settings to use system blocked numbers ui
-rw-r--r--src/com/android/dialer/compat/FilteredNumberCompat.java19
-rw-r--r--src/com/android/dialer/settings/DialerSettingsActivity.java6
-rw-r--r--tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java48
3 files changed, 69 insertions, 4 deletions
diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java
index c74ff9d1d..232504796 100644
--- a/src/com/android/dialer/compat/FilteredNumberCompat.java
+++ b/src/com/android/dialer/compat/FilteredNumberCompat.java
@@ -22,12 +22,16 @@ import android.app.FragmentManager;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
+import android.telecom.TelecomManager;
import android.telephony.PhoneNumberUtils;
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.FilteredNumberContract.FilteredNumber;
@@ -37,6 +41,7 @@ import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes;
import com.android.dialer.filterednumber.BlockNumberDialogFragment;
import com.android.dialer.filterednumber.BlockNumberDialogFragment.Callback;
import com.android.dialer.filterednumber.BlockedNumbersMigrator;
+import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity;
import com.android.dialer.filterednumber.MigrateBlockedNumbersDialogFragment;
import java.util.ArrayList;
@@ -268,4 +273,18 @@ public class FilteredNumberCompat {
private static boolean shouldShowMigrationDialog(boolean isBlocking) {
return isBlocking && canUseNewFiltering() && !hasMigratedToNewBlocking();
}
+
+ /**
+ * Creates the {@link Intent} which opens the blocked numbers management interface.
+ *
+ * @param context The {@link Context}.
+ * @return The intent.
+ */
+ public static Intent createManageBlockedNumbersIntent(Context context) {
+ if (canUseNewFiltering() && hasMigratedToNewBlocking()) {
+ return TelecomManagerUtil.createManageBlockedNumbersIntent(
+ (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE));
+ }
+ return new Intent(context, BlockedNumbersSettingsActivity.class);
+ }
}
diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java
index a18715760..bbcbd49fc 100644
--- a/src/com/android/dialer/settings/DialerSettingsActivity.java
+++ b/src/com/android/dialer/settings/DialerSettingsActivity.java
@@ -18,7 +18,6 @@ package com.android.dialer.settings;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.os.Build;
import android.os.Bundle;
import android.os.UserManager;
import android.preference.PreferenceManager;
@@ -29,12 +28,11 @@ import android.view.MenuItem;
import android.widget.Toast;
import com.android.contacts.common.compat.CompatUtils;
-import com.android.contacts.common.compat.SdkVersionOverride;
import com.android.contacts.common.compat.TelephonyManagerCompat;
import com.android.dialer.R;
+import com.android.dialer.compat.FilteredNumberCompat;
import com.android.dialer.compat.SettingsCompat;
import com.android.dialer.compat.UserManagerCompat;
-import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity;
import java.util.List;
@@ -99,7 +97,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity {
if (isPrimaryUser) {
Header blockedCallsHeader = new Header();
blockedCallsHeader.titleRes = R.string.manage_blocked_numbers_label;
- blockedCallsHeader.intent = new Intent(this, BlockedNumbersSettingsActivity.class);
+ blockedCallsHeader.intent = FilteredNumberCompat.createManageBlockedNumbersIntent(this);
target.add(blockedCallsHeader);
if (TelephonyManagerCompat.isTtyModeSupported(telephonyManager)
diff --git a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java
index a57e1c29c..5ee2f28e1 100644
--- a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java
+++ b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java
@@ -20,14 +20,17 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
+import android.content.ComponentName;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.provider.BlockedNumberContract.BlockedNumbers;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
+import android.util.Log;
import com.android.contacts.common.compat.CompatUtils;
import com.android.dialer.DialerApplication;
@@ -35,6 +38,7 @@ import com.android.dialer.database.FilteredNumberContract.FilteredNumber;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes;
+import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -179,6 +183,50 @@ public class FilteredNumberCompatTest extends AndroidTestCase {
FilteredNumberCompat.newBlockNumberContentValues(NON_E164_NUMBER, null, null));
}
+ public void testCreateManageBlockedNumbersIntent_NullContext() {
+ try {
+ FilteredNumberCompat.createManageBlockedNumbersIntent(null);
+ fail();
+ } catch (NullPointerException e) {}
+ }
+
+ public void testCreateManageBlockedNumbersIntent_M() {
+ if (CompatUtils.isNCompatible()) {
+ return;
+ }
+ assertEquals(new ComponentName(getContext(), BlockedNumbersSettingsActivity.class),
+ FilteredNumberCompat.createManageBlockedNumbersIntent(getContext()).getComponent());
+ }
+
+ public void testCreateManageBlockedNumbersIntent_N_Disabled_NotMigrated() {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ FilteredNumberCompat.setIsEnabledForTest(false);
+ assertEquals(new ComponentName(getContext(), BlockedNumbersSettingsActivity.class),
+ FilteredNumberCompat.createManageBlockedNumbersIntent(getContext()).getComponent());
+ }
+
+ public void testCreateManageBlockedNumbersIntent_N_Enabled_NotMigrated() {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ assertEquals(new ComponentName(getContext(), BlockedNumbersSettingsActivity.class),
+ FilteredNumberCompat.createManageBlockedNumbersIntent(getContext()).getComponent());
+ }
+
+ public void testCreateManageBlockedNumbersIntent_N_Enabled_Migrated() {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ when(mSharedPreferences
+ .getBoolean(FilteredNumberCompat.HAS_MIGRATED_TO_NEW_BLOCKING_KEY, false))
+ .thenReturn(true);
+ assertFalse(new ComponentName(getContext(), BlockedNumbersSettingsActivity.class)
+ .equals(FilteredNumberCompat.createManageBlockedNumbersIntent(getContext())
+ .getComponent()));
+ }
+
private ContentValues newExpectedContentValuesM(String number, String e164Number,
String countryIso) {
ContentValues contentValues = new ContentValues();