1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.dialer.calllog.datasources;
18 
19 import android.content.Context;
20 import android.database.sqlite.SQLiteDatabase;
21 import android.support.annotation.MainThread;
22 import android.support.annotation.WorkerThread;
23 import com.android.dialer.calllog.database.CallLogMutations;
24 
25 /** A source of data for one or more columns in the annotated call log. */
26 public interface CallLogDataSource {
27 
28   /**
29    * A lightweight check which runs frequently to detect if the annotated call log is out of date
30    * with respect to this data source.
31    *
32    * <p>This is typically used to detect external changes to the underlying data source which have
33    * been made in such a way that the dialer application was not notified.
34    *
35    * <p>Most implementations of this method will rely on some sort of last modified timestamp. If it
36    * is impossible for a data source to be modified without the dialer application being notified,
37    * this method may immediately return false.
38    */
39   @WorkerThread
isDirty(Context appContext)40   boolean isDirty(Context appContext);
41 
42   /**
43    * Computes the set of mutations necessary to update the annotated call log with respect to this
44    * data source.
45    *
46    * @param mutations the set of mutations which this method should contribute to. Note that it may
47    *     contain inserts from the system call log, and these inserts should be modified by each data
48    *     source.
49    */
50   @WorkerThread
fill( Context appContext, SQLiteDatabase readableDatabase, long lastRebuildTimeMillis, CallLogMutations mutations)51   void fill(
52       Context appContext,
53       SQLiteDatabase readableDatabase,
54       long lastRebuildTimeMillis,
55       CallLogMutations mutations);
56 
57   @MainThread
registerContentObservers( Context appContext, ContentObserverCallbacks contentObserverCallbacks)58   void registerContentObservers(
59       Context appContext, ContentObserverCallbacks contentObserverCallbacks);
60 
61   /**
62    * Methods which may optionally be called as a result of a data source's content observer firing.
63    */
64   interface ContentObserverCallbacks {
65     @MainThread
markDirtyAndNotify(Context appContext)66     void markDirtyAndNotify(Context appContext);
67   }
68 }
69