summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-03-06 10:54:00 -0800
committerBrandon Maxwell <maxwelb@google.com>2016-03-12 15:08:34 -0800
commit13825f0533ec175928406f5e9b79c54305e8c5b0 (patch)
tree2aa2cfc8ec4fee9f2c6eff4988bbb6c7890dc906 /src
parentf93604f330b592f6e572ce7631f779f1f05de731 (diff)
Adding sharedPref for blocked number migration
+ Users are shown a dialog when they're running on an SDK which supports the framework blocking solution, but they haven't yet migrated. In order to determine whether the user has migrated or not, a SharedPreference value is used. In a later CL which performs the migration, this value will be updated as the final step. Bug: 26664600 Change-Id: I5a12be643d0fb3b52ef408215779423bf0a2ddc7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/DialerApplication.java17
-rw-r--r--src/com/android/dialer/compat/FilteredNumberCompat.java30
2 files changed, 45 insertions, 2 deletions
diff --git a/src/com/android/dialer/DialerApplication.java b/src/com/android/dialer/DialerApplication.java
index 078b5510c..189c68221 100644
--- a/src/com/android/dialer/DialerApplication.java
+++ b/src/com/android/dialer/DialerApplication.java
@@ -17,16 +17,23 @@
package com.android.dialer;
import android.app.Application;
+import android.content.Context;
import android.os.Trace;
+import android.support.annotation.Nullable;
import com.android.contacts.common.extensions.ExtensionsFactory;
+import com.android.contacts.common.testing.NeededForTesting;
+import com.android.dialer.compat.FilteredNumberCompat;
public class DialerApplication extends Application {
private static final String TAG = "DialerApplication";
+ private static Context sContext;
+
@Override
public void onCreate() {
+ sContext = this;
Trace.beginSection(TAG + " onCreate");
super.onCreate();
Trace.beginSection(TAG + " ExtensionsFactory initialization");
@@ -34,4 +41,14 @@ public class DialerApplication extends Application {
Trace.endSection();
Trace.endSection();
}
+
+ @Nullable
+ public static Context getContext() {
+ return sContext;
+ }
+
+ @NeededForTesting
+ public static void setContextForTest(Context context) {
+ sContext = context;
+ }
}
diff --git a/src/com/android/dialer/compat/FilteredNumberCompat.java b/src/com/android/dialer/compat/FilteredNumberCompat.java
index 63a2a32cd..3ad45e87d 100644
--- a/src/com/android/dialer/compat/FilteredNumberCompat.java
+++ b/src/com/android/dialer/compat/FilteredNumberCompat.java
@@ -20,12 +20,15 @@ import com.google.common.base.Preconditions;
import android.content.ContentUris;
import android.content.ContentValues;
+import android.content.Context;
import android.net.Uri;
+import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.telephony.PhoneNumberUtils;
import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.testing.NeededForTesting;
+import com.android.dialer.DialerApplication;
import com.android.dialer.database.FilteredNumberContract.FilteredNumber;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns;
import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources;
@@ -43,9 +46,12 @@ import java.util.List;
*/
public class FilteredNumberCompat {
+ protected static final String HAS_MIGRATED_TO_NEW_BLOCKING_KEY = "migratedToNewBlocking";
+
// Flag to enable feature.
// TODO(maxwelb) remove when ready to enable new filtering.
private static final boolean isNewFilteringEnabled = false;
+
private static Boolean isEnabledForTest;
/**
@@ -114,8 +120,28 @@ public class FilteredNumberCompat {
* migration has been performed, {@code false} otherwise.
*/
public static boolean useNewFiltering() {
- // TODO(maxwelb): Add shared preference for when the Dialer blocked list has been migrated
- return canUseNewFiltering();
+ return canUseNewFiltering() && hasMigratedToNewBlocking();
+ }
+
+ /**
+ * @return {@code true} if the user has migrated to use
+ * {@link android.provider.BlockedNumberContract} blocking, {@code false} otherwise.
+ */
+ public static boolean hasMigratedToNewBlocking() {
+ return PreferenceManager.getDefaultSharedPreferences(DialerApplication.getContext())
+ .getBoolean(HAS_MIGRATED_TO_NEW_BLOCKING_KEY, false);
+ }
+
+ /**
+ * Called to inform this class whether the user has fully migrated to use
+ * {@link android.provider.BlockedNumberContract} blocking or not.
+ *
+ * @param hasMigrated {@code true} if the user has migrated, {@code false} otherwise.
+ */
+ @NeededForTesting
+ public static void setHasMigratedToNewBlocking(boolean hasMigrated) {
+ PreferenceManager.getDefaultSharedPreferences(DialerApplication.getContext()).edit()
+ .putBoolean(HAS_MIGRATED_TO_NEW_BLOCKING_KEY, hasMigrated).apply();
}
@NeededForTesting