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.datasources.CallLogDataSource; 20 import com.android.dialer.calllog.datasources.contacts.ContactsDataSource; 21 import com.android.dialer.calllog.datasources.systemcalllog.SystemCallLogDataSource; 22 import com.android.dialer.common.concurrent.DefaultDialerExecutorFactory; 23 import com.android.dialer.common.concurrent.DialerExecutorFactory; 24 import dagger.Binds; 25 import dagger.Module; 26 import dagger.Provides; 27 import java.util.Arrays; 28 import java.util.Collections; 29 import java.util.List; 30 31 /** Dagger module which satisfies call log dependencies. */ 32 @Module 33 public abstract class CallLogModule { 34 35 @Binds bindDialerExecutorFactory( DefaultDialerExecutorFactory defaultDialerExecutorFactory)36 abstract DialerExecutorFactory bindDialerExecutorFactory( 37 DefaultDialerExecutorFactory defaultDialerExecutorFactory); 38 39 @Provides provideCallLogDataSources( SystemCallLogDataSource systemCallLogDataSource, ContactsDataSource contactsDataSource)40 static DataSources provideCallLogDataSources( 41 SystemCallLogDataSource systemCallLogDataSource, ContactsDataSource contactsDataSource) { 42 // System call log must be first, see getDataSourcesExcludingSystemCallLog below. 43 List<CallLogDataSource> allDataSources = 44 Collections.unmodifiableList(Arrays.asList(systemCallLogDataSource, contactsDataSource)); 45 return new DataSources() { 46 @Override 47 public SystemCallLogDataSource getSystemCallLogDataSource() { 48 return systemCallLogDataSource; 49 } 50 51 @Override 52 public List<CallLogDataSource> getDataSourcesIncludingSystemCallLog() { 53 return allDataSources; 54 } 55 56 @Override 57 public List<CallLogDataSource> getDataSourcesExcludingSystemCallLog() { 58 return allDataSources.subList(1, allDataSources.size()); 59 } 60 }; 61 } 62 } 63