summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-06-28 16:14:49 -0700
committerCopybara-Service <copybara-piper@google.com>2018-06-28 16:26:35 -0700
commitc36785d230920498d3476d5f881ae5c55b4d2fb3 (patch)
tree458d9abfcab1260c1657d1a481d3b6adde67e8bf /java
parent80cafcbb7531b68e9acfadcb17c331a7c684b649 (diff)
downloadandroid_packages_apps_Dialer-c36785d230920498d3476d5f881ae5c55b4d2fb3.tar.gz
android_packages_apps_Dialer-c36785d230920498d3476d5f881ae5c55b4d2fb3.tar.bz2
android_packages_apps_Dialer-c36785d230920498d3476d5f881ae5c55b4d2fb3.zip
Avoid updating system call log cache when the call log is being built
The initial build can contain up to 1000 rows, which may be more the what the system call log can handle with a batch operation. Initial build does not create any additional information, so the cache does not need to be updated. This CL also limits the cache updater to 100 rows as a safety measure. TEST=TAP Bug: 77292040 Test: TAP PiperOrigin-RevId: 202563376 Change-Id: Iff515ae2b76a19d63d9d794a0d443cc8332e83a4
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/calllog/CallLogCacheUpdater.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/java/com/android/dialer/calllog/CallLogCacheUpdater.java b/java/com/android/dialer/calllog/CallLogCacheUpdater.java
index a7b2b3d0d..b3130e964 100644
--- a/java/com/android/dialer/calllog/CallLogCacheUpdater.java
+++ b/java/com/android/dialer/calllog/CallLogCacheUpdater.java
@@ -25,6 +25,7 @@ import android.os.RemoteException;
import android.provider.CallLog;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.support.annotation.VisibleForTesting;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.NumberAttributes;
import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.AnnotatedCallLog;
@@ -33,6 +34,7 @@ import com.android.dialer.common.LogUtil;
import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor;
import com.android.dialer.inject.ApplicationContext;
import com.android.dialer.protos.ProtoParsers;
+import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import java.util.ArrayList;
@@ -49,13 +51,23 @@ public final class CallLogCacheUpdater {
private final Context appContext;
private final ListeningExecutorService backgroundExecutor;
+ private final CallLogState callLogState;
+
+ /**
+ * Maximum numbers of operations the updater can do. Each transaction to the system call log will
+ * trigger a call log refresh, so the updater can only do a single batch. If there are more
+ * operations it will be truncated. Under normal circumstances there will only be 1 operation
+ */
+ @VisibleForTesting static final int CACHE_UPDATE_LIMIT = 100;
@Inject
CallLogCacheUpdater(
@ApplicationContext Context appContext,
- @BackgroundExecutor ListeningExecutorService backgroundExecutor) {
+ @BackgroundExecutor ListeningExecutorService backgroundExecutor,
+ CallLogState callLogState) {
this.appContext = appContext;
this.backgroundExecutor = backgroundExecutor;
+ this.callLogState = callLogState;
}
/**
@@ -66,17 +78,27 @@ public final class CallLogCacheUpdater {
* has changed
*/
public ListenableFuture<Void> updateCache(CallLogMutations mutations) {
- return backgroundExecutor.submit(
- () -> {
+ return Futures.transform(
+ callLogState.isBuilt(),
+ isBuilt -> {
+ if (!isBuilt) {
+ // Initial build might need to update 1000 caches, which may overflow the batch
+ // operation limit. The initial data was already built with the cache, there's no need
+ // to update it.
+ LogUtil.i("CallLogCacheUpdater.updateCache", "not updating cache for initial build");
+ return null;
+ }
updateCacheInternal(mutations);
return null;
- });
+ },
+ backgroundExecutor);
}
private void updateCacheInternal(CallLogMutations mutations) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
Stream.concat(
mutations.getInserts().entrySet().stream(), mutations.getUpdates().entrySet().stream())
+ .limit(CACHE_UPDATE_LIMIT)
.forEach(
entry -> {
ContentValues values = entry.getValue();