use of com.android.dialer.calllog.datasources.CallLogDataSource in project android_packages_apps_Dialer by LineageOS.
the class RefreshAnnotatedCallLogWorker method rebuild.
// Uses try-with-resources
@TargetApi(Build.VERSION_CODES.M)
@WorkerThread
private void rebuild(Context appContext) throws RemoteException, OperationApplicationException {
Assert.isWorkerThread();
CallLogMutations mutations = new CallLogMutations();
// System call log data source must go first!
CallLogDataSource systemCallLogDataSource = dataSources.getSystemCallLogDataSource();
String dataSourceName = getName(systemCallLogDataSource);
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "filling %s", dataSourceName);
long startTime = System.currentTimeMillis();
systemCallLogDataSource.fill(appContext, mutations);
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "%s.fill took: %dms", dataSourceName, System.currentTimeMillis() - startTime);
for (CallLogDataSource dataSource : dataSources.getDataSourcesExcludingSystemCallLog()) {
dataSourceName = getName(dataSource);
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "filling %s", dataSourceName);
startTime = System.currentTimeMillis();
dataSource.fill(appContext, mutations);
LogUtil.i("CallLogFramework.rebuild", "%s.fill took: %dms", dataSourceName, System.currentTimeMillis() - startTime);
}
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "applying mutations to database");
startTime = System.currentTimeMillis();
CallLogDatabaseComponent.get(appContext).mutationApplier().applyToDatabase(mutations, appContext);
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "applyToDatabase took: %dms", System.currentTimeMillis() - startTime);
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
dataSourceName = getName(dataSource);
LogUtil.i("RefreshAnnotatedCallLogWorker.rebuild", "onSuccessfulFill'ing %s", dataSourceName);
startTime = System.currentTimeMillis();
dataSource.onSuccessfulFill(appContext);
LogUtil.i("CallLogFramework.rebuild", "%s.onSuccessfulFill took: %dms", dataSourceName, System.currentTimeMillis() - startTime);
}
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext);
sharedPreferences.edit().putBoolean(CallLogFramework.PREF_FORCE_REBUILD, false).apply();
}
use of com.android.dialer.calllog.datasources.CallLogDataSource in project android_packages_apps_Dialer by LineageOS.
the class RefreshAnnotatedCallLogWorker method rebuild.
private ListenableFuture<RefreshResult> rebuild(boolean isBuilt) {
CallLogMutations mutations = new CallLogMutations();
// Start by filling the data sources--the system call log data source must go first!
CallLogDataSource systemCallLogDataSource = dataSources.getSystemCallLogDataSource();
ListenableFuture<Void> fillFuture = systemCallLogDataSource.fill(mutations);
String systemEventName = eventNameForFill(systemCallLogDataSource, isBuilt);
futureTimer.applyTiming(fillFuture, systemEventName);
// passed from source to source.
for (CallLogDataSource dataSource : dataSources.getDataSourcesExcludingSystemCallLog()) {
fillFuture = Futures.transformAsync(fillFuture, unused -> {
ListenableFuture<Void> dataSourceFuture = dataSource.fill(mutations);
String eventName = eventNameForFill(dataSource, isBuilt);
futureTimer.applyTiming(dataSourceFuture, eventName);
return dataSourceFuture;
}, lightweightExecutorService);
}
futureTimer.applyTiming(fillFuture, eventNameForOverallFill(isBuilt));
// After all data sources are filled, apply mutations (at this point "fillFuture" is the result
// of filling the last data source).
ListenableFuture<Void> applyMutationsFuture = Futures.transformAsync(fillFuture, unused -> {
ListenableFuture<Void> mutationApplierFuture = mutationApplier.applyToDatabase(mutations, appContext);
futureTimer.applyTiming(mutationApplierFuture, eventNameForApplyMutations(isBuilt));
return mutationApplierFuture;
}, lightweightExecutorService);
Futures.addCallback(Futures.transformAsync(applyMutationsFuture, unused -> callLogCacheUpdater.updateCache(mutations), MoreExecutors.directExecutor()), new DefaultFutureCallback<>(), MoreExecutors.directExecutor());
// After mutations applied, call onSuccessfulFill for each data source (in parallel).
ListenableFuture<List<Void>> onSuccessfulFillFuture = Futures.transformAsync(applyMutationsFuture, unused -> {
List<ListenableFuture<Void>> onSuccessfulFillFutures = new ArrayList<>();
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
ListenableFuture<Void> dataSourceFuture = dataSource.onSuccessfulFill();
onSuccessfulFillFutures.add(dataSourceFuture);
String eventName = eventNameForOnSuccessfulFill(dataSource, isBuilt);
futureTimer.applyTiming(dataSourceFuture, eventName);
}
ListenableFuture<List<Void>> allFutures = Futures.allAsList(onSuccessfulFillFutures);
futureTimer.applyTiming(allFutures, eventNameForOverallOnSuccessfulFill(isBuilt));
return allFutures;
}, lightweightExecutorService);
// After onSuccessfulFill is called for every data source, write the shared pref.
return Futures.transform(onSuccessfulFillFuture, unused -> {
sharedPreferences.edit().putBoolean(SharedPrefKeys.FORCE_REBUILD, false).apply();
callLogState.markBuilt();
return mutations.isEmpty() ? RefreshResult.REBUILT_BUT_NO_CHANGES_NEEDED : RefreshResult.REBUILT_AND_CHANGES_NEEDED;
}, backgroundExecutorService);
}
use of com.android.dialer.calllog.datasources.CallLogDataSource in project android_packages_apps_Dialer by LineageOS.
the class CallLogFramework method disableDataSources.
private ListenableFuture<Void> disableDataSources() {
LogUtil.enterBlock("CallLogFramework.disableDataSources");
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
dataSource.unregisterContentObservers();
}
callLogState.clearData();
// Clear data only after all content observers have been disabled.
List<ListenableFuture<Void>> allFutures = new ArrayList<>();
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
allFutures.add(dataSource.clearData());
}
return Futures.transform(Futures.allAsList(allFutures), unused -> {
// Send a broadcast to the OldMainActivityPeer to remove the NewCallLogFragment and
// NewVoicemailFragment if it is currently attached. If this is not done, user interaction
// with the fragment could cause call log framework state to be unexpectedly written. For
// example scrolling could cause the AnnotatedCallLog to be read (which would trigger
// database creation).
LocalBroadcastManager.getInstance(appContext).sendBroadcastSync(new Intent("disableCallLogFramework"));
return null;
}, uiExecutor);
}
use of com.android.dialer.calllog.datasources.CallLogDataSource in project android_packages_apps_Dialer by LineageOS.
the class RefreshAnnotatedCallLogWorker method isDirty.
@WorkerThread
private boolean isDirty(Context appContext) {
Assert.isWorkerThread();
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
String dataSourceName = getName(dataSource);
long startTime = System.currentTimeMillis();
LogUtil.i("RefreshAnnotatedCallLogWorker.isDirty", "running isDirty for %s", dataSourceName);
boolean isDirty = dataSource.isDirty(appContext);
LogUtil.i("RefreshAnnotatedCallLogWorker.isDirty", "%s.isDirty returned %b in %dms", dataSourceName, isDirty, System.currentTimeMillis() - startTime);
if (isDirty) {
return true;
}
}
return false;
}
use of com.android.dialer.calllog.datasources.CallLogDataSource in project android_packages_apps_Dialer by LineageOS.
the class RefreshAnnotatedCallLogWorker method isDirty.
private ListenableFuture<Boolean> isDirty() {
List<ListenableFuture<Boolean>> isDirtyFutures = new ArrayList<>();
for (CallLogDataSource dataSource : dataSources.getDataSourcesIncludingSystemCallLog()) {
ListenableFuture<Boolean> dataSourceDirty = dataSource.isDirty();
isDirtyFutures.add(dataSourceDirty);
String eventName = String.format(Metrics.IS_DIRTY_TEMPLATE, dataSource.getLoggingName());
futureTimer.applyTiming(dataSourceDirty, eventName, LogCatMode.LOG_VALUES);
}
// Simultaneously invokes isDirty on all data sources, returning as soon as one returns true.
ListenableFuture<Boolean> isDirtyFuture = DialerFutures.firstMatching(isDirtyFutures, Preconditions::checkNotNull, false);
futureTimer.applyTiming(isDirtyFuture, Metrics.IS_DIRTY_EVENT_NAME, LogCatMode.LOG_VALUES);
return isDirtyFuture;
}
Aggregations