From fb112d870c3a564d2dcb0e72dcdcabb6e0375520 Mon Sep 17 00:00:00 2001 From: twyen Date: Fri, 5 Jan 2018 11:52:45 -0800 Subject: Implement dialer blocked number phone lookup This CL implements looking up the dialer internal database for blocked numbers when the system database is not available yet. Data is only invalidated when dialer is alive since that is the only time blocked numbers can be set and removed. Bug: 70989538,70989547 Test: DialerBlockedNumberPhoneLookupTest PiperOrigin-RevId: 180956355 Change-Id: Ie7acf091bf58a074d0a1ee39613fad035d2e6e60 --- .../android/dialer/calllog/CallLogFramework.java | 4 ++- .../phonelookup/PhoneLookupDataSource.java | 40 +++++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'java/com/android/dialer/calllog') diff --git a/java/com/android/dialer/calllog/CallLogFramework.java b/java/com/android/dialer/calllog/CallLogFramework.java index e4bb4c89a..c9d5f0907 100644 --- a/java/com/android/dialer/calllog/CallLogFramework.java +++ b/java/com/android/dialer/calllog/CallLogFramework.java @@ -20,6 +20,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.support.annotation.MainThread; import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; import com.android.dialer.buildtype.BuildType; import com.android.dialer.calllog.datasources.CallLogDataSource; import com.android.dialer.calllog.datasources.DataSources; @@ -38,7 +39,8 @@ import javax.inject.Singleton; @Singleton public final class CallLogFramework implements CallLogDataSource.ContentObserverCallbacks { - static final String PREF_FORCE_REBUILD = "callLogFrameworkForceRebuild"; + @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) + public static final String PREF_FORCE_REBUILD = "callLogFrameworkForceRebuild"; private final DataSources dataSources; private final SharedPreferences sharedPreferences; diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 214862793..6ec11ad13 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -33,14 +33,15 @@ import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.Ann import com.android.dialer.calllog.datasources.CallLogDataSource; import com.android.dialer.calllog.datasources.CallLogMutations; import com.android.dialer.calllog.datasources.util.RowCombiner; +import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.common.concurrent.Annotations.LightweightExecutor; import com.android.dialer.phonelookup.PhoneLookup; import com.android.dialer.phonelookup.PhoneLookupInfo; -import com.android.dialer.phonelookup.PhoneLookupSelector; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract; import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory; +import com.android.dialer.phonelookup.selector.PhoneLookupSelector; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -63,9 +64,11 @@ import javax.inject.Inject; * Responsible for maintaining the columns in the annotated call log which are derived from phone * numbers. */ -public final class PhoneLookupDataSource implements CallLogDataSource { +public final class PhoneLookupDataSource + implements CallLogDataSource, PhoneLookup.ContentObserverCallbacks { private final PhoneLookup phoneLookup; + private final PhoneLookupSelector phoneLookupSelector; private final ListeningExecutorService backgroundExecutorService; private final ListeningExecutorService lightweightExecutorService; @@ -86,12 +89,16 @@ public final class PhoneLookupDataSource implements CallLogDataSource { */ private final Set phoneLookupHistoryRowsToDelete = new ArraySet<>(); + private CallLogDataSource.ContentObserverCallbacks dataSourceContentObserverCallbacks; + @Inject PhoneLookupDataSource( PhoneLookup phoneLookup, + PhoneLookupSelector phoneLookupSelector, @BackgroundExecutor ListeningExecutorService backgroundExecutorService, @LightweightExecutor ListeningExecutorService lightweightExecutorService) { this.phoneLookup = phoneLookup; + this.phoneLookupSelector = phoneLookupSelector; this.backgroundExecutorService = backgroundExecutorService; this.lightweightExecutorService = lightweightExecutorService; } @@ -275,8 +282,16 @@ public final class PhoneLookupDataSource implements CallLogDataSource { @MainThread @Override public void registerContentObservers( - Context appContext, ContentObserverCallbacks contentObserverCallbacks) { - // No content observers required for this data source. + Context appContext, CallLogDataSource.ContentObserverCallbacks contentObserverCallbacks) { + dataSourceContentObserverCallbacks = contentObserverCallbacks; + phoneLookup.registerContentObservers(appContext, this); + } + + @MainThread + @Override + public void markDirtyAndNotify(Context appContext) { + Assert.isMainThread(); + dataSourceContentObserverCallbacks.markDirtyAndNotify(appContext); } private static ImmutableSet @@ -455,7 +470,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { })); } - private static void populateInserts( + private void populateInserts( ImmutableMap existingInfo, CallLogMutations mutations) { for (Entry entry : mutations.getInserts().entrySet()) { long id = entry.getKey(); @@ -468,7 +483,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { } } - private static void updateMutations( + private void updateMutations( ImmutableMap updatesToApply, CallLogMutations mutations) { for (Entry entry : updatesToApply.entrySet()) { long id = entry.getKey(); @@ -554,17 +569,16 @@ public final class PhoneLookupDataSource implements CallLogDataSource { return normalizedNumbersToDelete; } - private static void updateContentValues( - ContentValues contentValues, PhoneLookupInfo phoneLookupInfo) { - contentValues.put(AnnotatedCallLog.NAME, PhoneLookupSelector.selectName(phoneLookupInfo)); + private void updateContentValues(ContentValues contentValues, PhoneLookupInfo phoneLookupInfo) { + contentValues.put(AnnotatedCallLog.NAME, phoneLookupSelector.selectName(phoneLookupInfo)); contentValues.put( - AnnotatedCallLog.PHOTO_URI, PhoneLookupSelector.selectPhotoUri(phoneLookupInfo)); + AnnotatedCallLog.PHOTO_URI, phoneLookupSelector.selectPhotoUri(phoneLookupInfo)); contentValues.put( - AnnotatedCallLog.PHOTO_ID, PhoneLookupSelector.selectPhotoId(phoneLookupInfo)); + AnnotatedCallLog.PHOTO_ID, phoneLookupSelector.selectPhotoId(phoneLookupInfo)); contentValues.put( - AnnotatedCallLog.LOOKUP_URI, PhoneLookupSelector.selectLookupUri(phoneLookupInfo)); + AnnotatedCallLog.LOOKUP_URI, phoneLookupSelector.selectLookupUri(phoneLookupInfo)); contentValues.put( - AnnotatedCallLog.NUMBER_TYPE_LABEL, PhoneLookupSelector.selectNumberLabel(phoneLookupInfo)); + AnnotatedCallLog.NUMBER_TYPE_LABEL, phoneLookupSelector.selectNumberLabel(phoneLookupInfo)); contentValues.put( AnnotatedCallLog.CAN_REPORT_AS_INVALID_NUMBER, PhoneLookupSelector.canReportAsInvalidNumber(phoneLookupInfo)); -- cgit v1.2.3