/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package com.android.dialer.calllog; import android.content.ContentProviderOperation; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; import android.content.OperationApplicationException; 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; import com.android.dialer.calllog.datasources.CallLogMutations; 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; import java.util.Arrays; import java.util.stream.Stream; import javax.inject.Inject; /** * Update {@link Calls#CACHED_NAME} and other cached columns after the annotated call log has been * updated. Dialer does not read these columns but other apps relies on it. */ 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, CallLogState callLogState) { this.appContext = appContext; this.backgroundExecutor = backgroundExecutor; this.callLogState = callLogState; } /** * Extracts inserts and updates from {@code mutations} to update the 'cached' columns in the * system call log. * *
If the cached columns are non-empty, it will only be updated if {@link Calls#CACHED_NAME}
* has changed
*/
public ListenableFuture