Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63657890 authored by zachh's avatar zachh Committed by Weijia Xu
Browse files

Removed appContext from CallLogDataSource and PhoneLookup.

Impls can access appContext via dagger.

Test: existing
PiperOrigin-RevId: 189974157
Change-Id: Ie64d2c6f9ba08fc914d3c31f7e014c2beef3ab00
parent 5ce34544
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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.
+4 −4
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ public class RefreshAnnotatedCallLogWorker {
  private ListenableFuture<Boolean> isDirty() {
    List<ListenableFuture<Boolean>> isDirtyFutures = new ArrayList<>();
    for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
      ListenableFuture<Boolean> dataSourceDirty = dataSource.isDirty(appContext);
      ListenableFuture<Boolean> 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<Void> fillFuture = systemCallLogDataSource.fill(appContext, mutations);
    ListenableFuture<Void> 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<Void> dataSourceFuture = dataSource.fill(appContext, mutations);
                ListenableFuture<Void> dataSourceFuture = dataSource.fill(mutations);
                String eventName = eventNameForFill(dataSource, isBuilt);
                futureTimer.applyTiming(dataSourceFuture, eventName);
                return dataSourceFuture;
@@ -215,7 +215,7 @@ public class RefreshAnnotatedCallLogWorker {
              List<ListenableFuture<Void>> onSuccessfulFillFutures = new ArrayList<>();
              for (CallLogDataSource dataSource :
                  dataSources.getDataSourcesIncludingSystemCallLog()) {
                ListenableFuture<Void> dataSourceFuture = dataSource.onSuccessfulFill(appContext);
                ListenableFuture<Void> dataSourceFuture = dataSource.onSuccessfulFill();
                onSuccessfulFillFutures.add(dataSourceFuture);
                String eventName = eventNameForOnSuccessfulFill(dataSource, isBuilt);
                futureTimer.applyTiming(dataSourceFuture, eventName);
+13 −15
Original line number Diff line number Diff line
@@ -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.
 *
 * <ol>
 *   <li>{@link #isDirty(Context)}: Invoked only if the framework doesn't yet know if a rebuild is
 *   <li>{@link #isDirty()}: Invoked only if the framework doesn't yet know if a rebuild is
 *       necessary.
 *   <li>{@link #fill(Context, CallLogMutations)}: Invoked only if the framework determined a
 *       rebuild is necessary.
 *   <li>{@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.
 *   <li>{@link #fill(CallLogMutations)}: Invoked only if the framework determined a rebuild is
 *       necessary.
 *   <li>{@link #onSuccessfulFill()}: Invoked if and only if fill was previously called and the
 *       mutations provided by the previous fill operation succeeded in being applied.
 * </ol>
 *
 * <p>Because {@link #isDirty(Context)} is not always invoked, {@link #fill(Context,
 * CallLogMutations)} shouldn't rely on any state saved during {@link #isDirty(Context)}. It
 * <em>is</em> safe to assume that {@link #onSuccessfulFill(Context)} refers to the previous fill
 * operation.
 * <p>Because {@link #isDirty()} is not always invoked, {@link #fill(CallLogMutations)} shouldn't
 * rely on any state saved during {@link #isDirty()}. It <em>is</em> safe to assume that {@link
 * #onSuccessfulFill()} refers to the previous fill operation.
 *
 * <p>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<Boolean> isDirty(Context appContext);
  ListenableFuture<Boolean> 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<Void> fill(Context appContext, CallLogMutations mutations);
  ListenableFuture<Void> 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<Void> onSuccessfulFill(Context appContext);
  ListenableFuture<Void> onSuccessfulFill();

  /**
   * Combines raw annotated call log rows into a single coalesced row.
@@ -104,10 +102,10 @@ public interface CallLogDataSource {
  ContentValues coalesce(List<ContentValues> 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
+15 −11
Original line number Diff line number Diff line
@@ -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).
   *
   * <p>This is state saved between the {@link #fill(Context, CallLogMutations)} and {@link
   * #onSuccessfulFill(Context)} operations.
   * <p>This is state saved between the {@link CallLogDataSource#fill(CallLogMutations)} and {@link
   * CallLogDataSource#onSuccessfulFill()} operations.
   */
  private final Map<String, PhoneLookupInfo> 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.
   *
   * <p>This is state saved between the {@link #fill(Context, CallLogMutations)} and {@link
   * #onSuccessfulFill(Context)} operations.
   * <p>This is state saved between the {@link CallLogDataSource#fill(CallLogMutations)} and {@link
   * CallLogDataSource#onSuccessfulFill()} operations.
   */
  private final Set<String> 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<Boolean> isDirty(Context appContext) {
  public ListenableFuture<Boolean> isDirty() {
    ListenableFuture<ImmutableSet<DialerPhoneNumber>> phoneNumbers =
        backgroundExecutorService.submit(
            () -> queryDistinctDialerPhoneNumbersFromAnnotatedCallLog(appContext));
@@ -139,7 +143,7 @@ public final class PhoneLookupDataSource implements CallLogDataSource {
   * </ul>
   */
  @Override
  public ListenableFuture<Void> fill(Context appContext, CallLogMutations mutations) {
  public ListenableFuture<Void> 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<Void> onSuccessfulFill(Context appContext) {
  public ListenableFuture<Void> onSuccessfulFill() {
    // First update and/or delete the appropriate rows in PhoneLookupHistory.
    ListenableFuture<Void> 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
+11 −7
Original line number Diff line number Diff line
@@ -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<Boolean> isDirty(Context appContext) {
  public ListenableFuture<Boolean> isDirty() {
    return backgroundExecutorService.submit(this::isDirtyInternal);
  }

  @Override
  public ListenableFuture<Void> fill(Context appContext, CallLogMutations mutations) {
    return backgroundExecutorService.submit(() -> fillInternal(appContext, mutations));
  public ListenableFuture<Void> fill(CallLogMutations mutations) {
    return backgroundExecutorService.submit(() -> fillInternal(mutations));
  }

  @Override
  public ListenableFuture<Void> onSuccessfulFill(Context appContext) {
  public ListenableFuture<Void> 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;
Loading