From 636578906c1ae45a5514059afd8279277c106b9b Mon Sep 17 00:00:00 2001 From: zachh Date: Wed, 21 Mar 2018 15:03:30 -0700 Subject: Removed appContext from CallLogDataSource and PhoneLookup. Impls can access appContext via dagger. Test: existing PiperOrigin-RevId: 189974157 Change-Id: Ie64d2c6f9ba08fc914d3c31f7e014c2beef3ab00 --- .../android/dialer/calllog/CallLogFramework.java | 4 ++-- .../calllog/RefreshAnnotatedCallLogWorker.java | 8 +++---- .../calllog/datasources/CallLogDataSource.java | 28 ++++++++++------------ .../phonelookup/PhoneLookupDataSource.java | 26 +++++++++++--------- .../systemcalllog/SystemCallLogDataSource.java | 18 ++++++++------ .../datasources/voicemail/VoicemailDataSource.java | 17 ++++++++----- .../android/dialer/phonelookup/PhoneLookup.java | 5 ++-- .../DialerBlockedNumberPhoneLookup.java | 4 ++-- .../SystemBlockedNumberPhoneLookup.java | 4 ++-- .../composite/CompositePhoneLookup.java | 13 +++++----- .../cp2/Cp2DefaultDirectoryPhoneLookup.java | 4 ++-- .../cp2/Cp2ExtendedDirectoryPhoneLookup.java | 4 ++-- .../dialer/phonelookup/spam/SpamPhoneLookup.java | 5 ++-- 13 files changed, 74 insertions(+), 66 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/calllog/CallLogFramework.java b/java/com/android/dialer/calllog/CallLogFramework.java index 365e4d7c0..936f2bbf6 100644 --- a/java/com/android/dialer/calllog/CallLogFramework.java +++ b/java/com/android/dialer/calllog/CallLogFramework.java @@ -63,7 +63,7 @@ public final class CallLogFramework { // TODO(zachh): Find a way to access Main#isNewUiEnabled without creating a circular dependency. if (ConfigProviderBindings.get(appContext).getBoolean("is_nui_shortcut_enabled", false)) { for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) { - dataSource.registerContentObservers(appContext); + dataSource.registerContentObservers(); } } else { LogUtil.i("CallLogFramework.registerContentObservers", "not registering content observers"); @@ -80,7 +80,7 @@ public final class CallLogFramework { } for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) { - dataSource.unregisterContentObservers(appContext); + dataSource.unregisterContentObservers(); } // Clear data only after all content observers have been disabled. diff --git a/java/com/android/dialer/calllog/RefreshAnnotatedCallLogWorker.java b/java/com/android/dialer/calllog/RefreshAnnotatedCallLogWorker.java index c399b05ea..32c278838 100644 --- a/java/com/android/dialer/calllog/RefreshAnnotatedCallLogWorker.java +++ b/java/com/android/dialer/calllog/RefreshAnnotatedCallLogWorker.java @@ -154,7 +154,7 @@ public class RefreshAnnotatedCallLogWorker { private ListenableFuture isDirty() { List> isDirtyFutures = new ArrayList<>(); for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) { - ListenableFuture dataSourceDirty = dataSource.isDirty(appContext); + ListenableFuture dataSourceDirty = dataSource.isDirty(); isDirtyFutures.add(dataSourceDirty); String eventName = String.format(Metrics.IS_DIRTY_TEMPLATE, dataSource.getClass().getSimpleName()); @@ -172,7 +172,7 @@ public class RefreshAnnotatedCallLogWorker { // Start by filling the data sources--the system call log data source must go first! CallLogDataSource systemCallLogDataSource = dataSources.getSystemCallLogDataSource(); - ListenableFuture fillFuture = systemCallLogDataSource.fill(appContext, mutations); + ListenableFuture fillFuture = systemCallLogDataSource.fill(mutations); String systemEventName = eventNameForFill(systemCallLogDataSource, isBuilt); futureTimer.applyTiming(fillFuture, systemEventName); @@ -184,7 +184,7 @@ public class RefreshAnnotatedCallLogWorker { Futures.transformAsync( fillFuture, unused -> { - ListenableFuture dataSourceFuture = dataSource.fill(appContext, mutations); + ListenableFuture dataSourceFuture = dataSource.fill(mutations); String eventName = eventNameForFill(dataSource, isBuilt); futureTimer.applyTiming(dataSourceFuture, eventName); return dataSourceFuture; @@ -215,7 +215,7 @@ public class RefreshAnnotatedCallLogWorker { List> onSuccessfulFillFutures = new ArrayList<>(); for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) { - ListenableFuture dataSourceFuture = dataSource.onSuccessfulFill(appContext); + ListenableFuture dataSourceFuture = dataSource.onSuccessfulFill(); onSuccessfulFillFutures.add(dataSourceFuture); String eventName = eventNameForOnSuccessfulFill(dataSource, isBuilt); futureTimer.applyTiming(dataSourceFuture, eventName); diff --git a/java/com/android/dialer/calllog/datasources/CallLogDataSource.java b/java/com/android/dialer/calllog/datasources/CallLogDataSource.java index fa3b6a9df..f6796c767 100644 --- a/java/com/android/dialer/calllog/datasources/CallLogDataSource.java +++ b/java/com/android/dialer/calllog/datasources/CallLogDataSource.java @@ -17,7 +17,6 @@ package com.android.dialer.calllog.datasources; import android.content.ContentValues; -import android.content.Context; import android.support.annotation.MainThread; import android.support.annotation.WorkerThread; import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract; @@ -32,18 +31,17 @@ import java.util.List; * always invoked. * *
    - *
  1. {@link #isDirty(Context)}: Invoked only if the framework doesn't yet know if a rebuild is + *
  2. {@link #isDirty()}: Invoked only if the framework doesn't yet know if a rebuild is * necessary. - *
  3. {@link #fill(Context, CallLogMutations)}: Invoked only if the framework determined a - * rebuild is necessary. - *
  4. {@link #onSuccessfulFill(Context)}: Invoked if and only if fill was previously called and - * the mutations provided by the previous fill operation succeeded in being applied. + *
  5. {@link #fill(CallLogMutations)}: Invoked only if the framework determined a rebuild is + * necessary. + *
  6. {@link #onSuccessfulFill()}: Invoked if and only if fill was previously called and the + * mutations provided by the previous fill operation succeeded in being applied. *
* - *

Because {@link #isDirty(Context)} is not always invoked, {@link #fill(Context, - * CallLogMutations)} shouldn't rely on any state saved during {@link #isDirty(Context)}. It - * is safe to assume that {@link #onSuccessfulFill(Context)} refers to the previous fill - * operation. + *

Because {@link #isDirty()} is not always invoked, {@link #fill(CallLogMutations)} shouldn't + * rely on any state saved during {@link #isDirty()}. It is safe to assume that {@link + * #onSuccessfulFill()} refers to the previous fill operation. * *

The same data source objects may be reused across multiple checkDirtyAndRebuild cycles, so * implementors should take care to clear any internal state at the start of a new cycle. @@ -65,7 +63,7 @@ public interface CallLogDataSource { * * @see CallLogDataSource class doc for complete lifecyle information */ - ListenableFuture isDirty(Context appContext); + ListenableFuture isDirty(); /** * Computes the set of mutations necessary to update the annotated call log with respect to this @@ -76,7 +74,7 @@ public interface CallLogDataSource { * contain inserts from the system call log, and these inserts should be modified by each data * source. */ - ListenableFuture fill(Context appContext, CallLogMutations mutations); + ListenableFuture fill(CallLogMutations mutations); /** * Called after database mutations have been applied to all data sources. This is useful for @@ -85,7 +83,7 @@ public interface CallLogDataSource { * * @see CallLogDataSource class doc for complete lifecyle information */ - ListenableFuture onSuccessfulFill(Context appContext); + ListenableFuture onSuccessfulFill(); /** * Combines raw annotated call log rows into a single coalesced row. @@ -104,10 +102,10 @@ public interface CallLogDataSource { ContentValues coalesce(List individualRowsSortedByTimestampDesc); @MainThread - void registerContentObservers(Context appContext); + void registerContentObservers(); @MainThread - void unregisterContentObservers(Context appContext); + void unregisterContentObservers(); /** * Clear any data written by this data source. This is called when the new call log framework has diff --git a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java index 615a457e3..0de987308 100644 --- a/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java +++ b/java/com/android/dialer/calllog/datasources/phonelookup/PhoneLookupDataSource.java @@ -37,6 +37,7 @@ 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.inject.ApplicationContext; import com.android.dialer.phonelookup.PhoneLookup; import com.android.dialer.phonelookup.PhoneLookupInfo; import com.android.dialer.phonelookup.composite.CompositePhoneLookup; @@ -66,6 +67,7 @@ import javax.inject.Inject; */ public final class PhoneLookupDataSource implements CallLogDataSource { + private final Context appContext; private final CompositePhoneLookup compositePhoneLookup; private final ListeningExecutorService backgroundExecutorService; private final ListeningExecutorService lightweightExecutorService; @@ -73,8 +75,8 @@ public final class PhoneLookupDataSource implements CallLogDataSource { /** * Keyed by normalized number (the primary key for PhoneLookupHistory). * - *

This is state saved between the {@link #fill(Context, CallLogMutations)} and {@link - * #onSuccessfulFill(Context)} operations. + *

This is state saved between the {@link CallLogDataSource#fill(CallLogMutations)} and {@link + * CallLogDataSource#onSuccessfulFill()} operations. */ private final Map phoneLookupHistoryRowsToUpdate = new ArrayMap<>(); @@ -82,8 +84,8 @@ public final class PhoneLookupDataSource implements CallLogDataSource { * Normalized numbers (the primary key for PhoneLookupHistory) which should be deleted from * PhoneLookupHistory. * - *

This is state saved between the {@link #fill(Context, CallLogMutations)} and {@link - * #onSuccessfulFill(Context)} operations. + *

This is state saved between the {@link CallLogDataSource#fill(CallLogMutations)} and {@link + * CallLogDataSource#onSuccessfulFill()} operations. */ private final Set phoneLookupHistoryRowsToDelete = new ArraySet<>(); @@ -91,10 +93,12 @@ public final class PhoneLookupDataSource implements CallLogDataSource { @Inject PhoneLookupDataSource( + @ApplicationContext Context appContext, CompositePhoneLookup compositePhoneLookup, @BackgroundExecutor ListeningExecutorService backgroundExecutorService, @LightweightExecutor ListeningExecutorService lightweightExecutorService, PhoneLookupHistoryDatabaseHelper phoneLookupHistoryDatabaseHelper) { + this.appContext = appContext; this.compositePhoneLookup = compositePhoneLookup; this.backgroundExecutorService = backgroundExecutorService; this.lightweightExecutorService = lightweightExecutorService; @@ -102,7 +106,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { } @Override - public ListenableFuture isDirty(Context appContext) { + public ListenableFuture isDirty() { ListenableFuture> phoneNumbers = backgroundExecutorService.submit( () -> queryDistinctDialerPhoneNumbersFromAnnotatedCallLog(appContext)); @@ -139,7 +143,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { * */ @Override - public ListenableFuture fill(Context appContext, CallLogMutations mutations) { + public ListenableFuture fill(CallLogMutations mutations) { LogUtil.v( "PhoneLookupDataSource.fill", "processing mutations (inserts: %d, updates: %d, deletes: %d)", @@ -243,7 +247,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource { } @Override - public ListenableFuture onSuccessfulFill(Context appContext) { + public ListenableFuture onSuccessfulFill() { // First update and/or delete the appropriate rows in PhoneLookupHistory. ListenableFuture writePhoneLookupHistory = backgroundExecutorService.submit(() -> writePhoneLookupHistory(appContext)); @@ -296,13 +300,13 @@ public final class PhoneLookupDataSource implements CallLogDataSource { @MainThread @Override - public void registerContentObservers(Context appContext) { - compositePhoneLookup.registerContentObservers(appContext); + public void registerContentObservers() { + compositePhoneLookup.registerContentObservers(); } @Override - public void unregisterContentObservers(Context appContext) { - compositePhoneLookup.unregisterContentObservers(appContext); + public void unregisterContentObservers() { + compositePhoneLookup.unregisterContentObservers(); } @Override diff --git a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java index e07996177..6fd19dd17 100644 --- a/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java +++ b/java/com/android/dialer/calllog/datasources/systemcalllog/SystemCallLogDataSource.java @@ -52,6 +52,7 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.compat.android.provider.VoicemailCompat; +import com.android.dialer.inject.ApplicationContext; import com.android.dialer.phonenumberproto.DialerPhoneNumberUtil; import com.android.dialer.storage.Unencrypted; import com.android.dialer.telecom.TelecomUtil; @@ -79,6 +80,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { @VisibleForTesting static final String PREF_LAST_TIMESTAMP_PROCESSED = "systemCallLogLastTimestampProcessed"; + private final Context appContext; private final ListeningExecutorService backgroundExecutorService; private final MarkDirtyObserver markDirtyObserver; private final SharedPreferences sharedPreferences; @@ -88,10 +90,12 @@ public class SystemCallLogDataSource implements CallLogDataSource { @Inject SystemCallLogDataSource( + @ApplicationContext Context appContext, @BackgroundExecutor ListeningExecutorService backgroundExecutorService, MarkDirtyObserver markDirtyObserver, @Unencrypted SharedPreferences sharedPreferences, AnnotatedCallLogDatabaseHelper annotatedCallLogDatabaseHelper) { + this.appContext = appContext; this.backgroundExecutorService = backgroundExecutorService; this.markDirtyObserver = markDirtyObserver; this.sharedPreferences = sharedPreferences; @@ -100,7 +104,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { @MainThread @Override - public void registerContentObservers(Context appContext) { + public void registerContentObservers() { Assert.isMainThread(); LogUtil.enterBlock("SystemCallLogDataSource.registerContentObservers"); @@ -130,7 +134,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { } @Override - public void unregisterContentObservers(Context appContext) { + public void unregisterContentObservers() { appContext.getContentResolver().unregisterContentObserver(markDirtyObserver); } @@ -151,17 +155,17 @@ public class SystemCallLogDataSource implements CallLogDataSource { } @Override - public ListenableFuture isDirty(Context appContext) { + public ListenableFuture isDirty() { return backgroundExecutorService.submit(this::isDirtyInternal); } @Override - public ListenableFuture fill(Context appContext, CallLogMutations mutations) { - return backgroundExecutorService.submit(() -> fillInternal(appContext, mutations)); + public ListenableFuture fill(CallLogMutations mutations) { + return backgroundExecutorService.submit(() -> fillInternal(mutations)); } @Override - public ListenableFuture onSuccessfulFill(Context appContext) { + public ListenableFuture onSuccessfulFill() { return backgroundExecutorService.submit(this::onSuccessfulFillInternal); } @@ -181,7 +185,7 @@ public class SystemCallLogDataSource implements CallLogDataSource { } @WorkerThread - private Void fillInternal(Context appContext, CallLogMutations mutations) { + private Void fillInternal(CallLogMutations mutations) { Assert.isWorkerThread(); lastTimestampProcessed = null; diff --git a/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java b/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java index 75c05139d..ab9288a1e 100644 --- a/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java +++ b/java/com/android/dialer/calllog/datasources/voicemail/VoicemailDataSource.java @@ -28,6 +28,7 @@ import com.android.dialer.calllog.datasources.CallLogMutations; import com.android.dialer.calllog.datasources.util.RowCombiner; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.compat.telephony.TelephonyManagerCompat; +import com.android.dialer.inject.ApplicationContext; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.PermissionsUtil; import com.google.common.util.concurrent.Futures; @@ -41,15 +42,19 @@ import javax.inject.Inject; /** Provide information for whether the call is a call to the voicemail inbox. */ public class VoicemailDataSource implements CallLogDataSource { + private final Context appContext; private final ListeningExecutorService backgroundExecutor; @Inject - VoicemailDataSource(@BackgroundExecutor ListeningExecutorService backgroundExecutor) { + VoicemailDataSource( + @ApplicationContext Context appContext, + @BackgroundExecutor ListeningExecutorService backgroundExecutor) { + this.appContext = appContext; this.backgroundExecutor = backgroundExecutor; } @Override - public ListenableFuture isDirty(Context appContext) { + public ListenableFuture isDirty() { // The isVoicemail status is immutable and permanent. The call will always show as "Voicemail" // even if the SIM is swapped. Dialing the row will result in some unexpected number after a SIM // swap but this is deemed acceptable. @@ -58,7 +63,7 @@ public class VoicemailDataSource implements CallLogDataSource { @Override @SuppressWarnings("missingPermission") - public ListenableFuture fill(Context appContext, CallLogMutations mutations) { + public ListenableFuture fill(CallLogMutations mutations) { if (!PermissionsUtil.hasReadPhoneStatePermissions(appContext)) { return Futures.immediateFuture(null); } @@ -94,7 +99,7 @@ public class VoicemailDataSource implements CallLogDataSource { } @Override - public ListenableFuture onSuccessfulFill(Context appContext) { + public ListenableFuture onSuccessfulFill() { return Futures.immediateFuture(null); } @@ -107,10 +112,10 @@ public class VoicemailDataSource implements CallLogDataSource { } @Override - public void registerContentObservers(Context appContext) {} + public void registerContentObservers() {} @Override - public void unregisterContentObservers(Context appContext) {} + public void unregisterContentObservers() {} @Override public ListenableFuture clearData() { diff --git a/java/com/android/dialer/phonelookup/PhoneLookup.java b/java/com/android/dialer/phonelookup/PhoneLookup.java index d4a1ddfbd..d11f023af 100644 --- a/java/com/android/dialer/phonelookup/PhoneLookup.java +++ b/java/com/android/dialer/phonelookup/PhoneLookup.java @@ -16,7 +16,6 @@ package com.android.dialer.phonelookup; -import android.content.Context; import android.support.annotation.MainThread; import com.android.dialer.DialerPhoneNumber; import com.google.common.collect.ImmutableMap; @@ -84,10 +83,10 @@ public interface PhoneLookup { ListenableFuture onSuccessfulBulkUpdate(); @MainThread - void registerContentObservers(Context appContext); + void registerContentObservers(); @MainThread - void unregisterContentObservers(Context appContext); + void unregisterContentObservers(); /** * Clear any data written by this lookup. This is called when the new call log framework has been diff --git a/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java b/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java index f5a249aed..ce879a995 100644 --- a/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java +++ b/java/com/android/dialer/phonelookup/blockednumber/DialerBlockedNumberPhoneLookup.java @@ -169,7 +169,7 @@ public final class DialerBlockedNumberPhoneLookup implements PhoneLookup clearData() { diff --git a/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java index 9110aa71f..e497989c7 100644 --- a/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java +++ b/java/com/android/dialer/phonelookup/cp2/Cp2ExtendedDirectoryPhoneLookup.java @@ -228,14 +228,14 @@ public final class Cp2ExtendedDirectoryPhoneLookup implements PhoneLookup clearData() { diff --git a/java/com/android/dialer/phonelookup/spam/SpamPhoneLookup.java b/java/com/android/dialer/phonelookup/spam/SpamPhoneLookup.java index 315f65819..6b77036cf 100644 --- a/java/com/android/dialer/phonelookup/spam/SpamPhoneLookup.java +++ b/java/com/android/dialer/phonelookup/spam/SpamPhoneLookup.java @@ -16,7 +16,6 @@ package com.android.dialer.phonelookup.spam; -import android.content.Context; import android.content.SharedPreferences; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; @@ -152,13 +151,13 @@ public final class SpamPhoneLookup implements PhoneLookup { } @Override - public void registerContentObservers(Context appContext) { + public void registerContentObservers() { // No content observer can be registered as Spam is not based on a content provider. // Each Spam implementation should be responsible for notifying any data changes. } @Override - public void unregisterContentObservers(Context appContext) {} + public void unregisterContentObservers() {} @Override public ListenableFuture clearData() { -- cgit v1.2.3