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;
18 
19 import com.android.dialer.calllog.database.CallLogDatabaseModule;
20 import com.android.dialer.calllog.datasources.CallLogDataSource;
21 import com.android.dialer.calllog.datasources.DataSources;
22 import com.android.dialer.calllog.datasources.phonelookup.PhoneLookupDataSource;
23 import com.android.dialer.calllog.datasources.systemcalllog.SystemCallLogDataSource;
24 import com.android.dialer.calllog.datasources.voicemail.VoicemailDataSource;
25 import com.android.dialer.inject.DialerVariant;
26 import com.android.dialer.inject.InstallIn;
27 import com.google.common.collect.ImmutableList;
28 import dagger.Module;
29 import dagger.Provides;
30 
31 /** Dagger module which satisfies call log dependencies. */
32 @InstallIn(variants = {DialerVariant.DIALER_TEST})
33 @Module(includes = CallLogDatabaseModule.class)
34 public abstract class CallLogModule {
35 
36   @Provides
provideCallLogDataSources( SystemCallLogDataSource systemCallLogDataSource, PhoneLookupDataSource phoneLookupDataSource, VoicemailDataSource voicemailDataSource)37   static DataSources provideCallLogDataSources(
38       SystemCallLogDataSource systemCallLogDataSource,
39       PhoneLookupDataSource phoneLookupDataSource,
40       VoicemailDataSource voicemailDataSource) {
41     // System call log must be first, see getDataSourcesExcludingSystemCallLog below.
42     ImmutableList<CallLogDataSource> allDataSources =
43         ImmutableList.of(systemCallLogDataSource, phoneLookupDataSource, voicemailDataSource);
44     return new DataSources() {
45       @Override
46       public SystemCallLogDataSource getSystemCallLogDataSource() {
47         return systemCallLogDataSource;
48       }
49 
50       @Override
51       public ImmutableList<CallLogDataSource> getDataSourcesIncludingSystemCallLog() {
52         return allDataSources;
53       }
54 
55       @Override
56       public ImmutableList<CallLogDataSource> getDataSourcesExcludingSystemCallLog() {
57         return allDataSources.subList(1, allDataSources.size());
58       }
59     };
60   }
61 }
62