1 /* 2 * Copyright (C) 2021 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.car.dialer.framework; 18 19 import android.bluetooth.BluetoothDevice; 20 import android.content.Context; 21 22 import androidx.lifecycle.LiveData; 23 24 import com.android.car.apps.common.util.LiveDataFunctions; 25 import com.android.car.dialer.livedata.CallHistoryLiveData; 26 import com.android.car.dialer.storage.FavoriteNumberRepository; 27 import com.android.car.dialer.ui.favorite.BluetoothFavoriteContactsLiveData; 28 import com.android.car.telephony.common.Contact; 29 import com.android.car.telephony.common.InMemoryPhoneBook; 30 import com.android.car.telephony.common.PhoneCallLog; 31 32 import java.util.Collections; 33 import java.util.List; 34 import java.util.Set; 35 36 import javax.inject.Named; 37 import javax.inject.Singleton; 38 39 import dagger.Module; 40 import dagger.Provides; 41 import dagger.hilt.InstallIn; 42 import dagger.hilt.android.qualifiers.ApplicationContext; 43 import dagger.hilt.components.SingletonComponent; 44 45 /** Module providing dependencies for single hfp connection running on the emulator. */ 46 @InstallIn(SingletonComponent.class) 47 @Module 48 public final class SingleHfpEmulatorModule { 49 @Singleton 50 @Named("Bluetooth") 51 @Provides provideBluetoothStateLiveData()52 static LiveData<Integer> provideBluetoothStateLiveData() { 53 return LiveDataFunctions.dataOf(/*enabled*/2); 54 } 55 56 @Singleton 57 @Named("Bluetooth") 58 @Provides provideBluetoothPairListLiveData()59 static LiveData<Set<BluetoothDevice>> provideBluetoothPairListLiveData() { 60 return LiveDataFunctions.dataOf(Collections.emptySet()); 61 } 62 63 @Singleton 64 @Named("Hfp") 65 @Provides provideHfpDeviceListLiveData()66 static LiveData<List<BluetoothDevice>> provideHfpDeviceListLiveData() { 67 return LiveDataFunctions.dataOf(Collections.emptyList()); 68 } 69 70 @Singleton 71 @Named("Hfp") 72 @Provides provideCurrentHfpDeviceLiveData()73 static LiveData<BluetoothDevice> provideCurrentHfpDeviceLiveData() { 74 return LiveDataFunctions.dataOf(null); 75 } 76 77 @Singleton 78 @Named("Hfp") 79 @Provides hasHfpDeviceConnectedLiveData()80 static LiveData<Boolean> hasHfpDeviceConnectedLiveData() { 81 return LiveDataFunctions.dataOf(true); 82 } 83 84 @Provides provideCallHistoryLiveData( @pplicationContext Context context)85 static LiveData<List<PhoneCallLog>> provideCallHistoryLiveData( 86 @ApplicationContext Context context) { 87 return CallHistoryLiveData.newInstance(context, null); 88 } 89 90 @Provides provideContactListLiveData()91 static LiveData<List<Contact>> provideContactListLiveData() { 92 return InMemoryPhoneBook.get().getContactsLiveDataByAccount(null); 93 } 94 95 @Provides 96 @Named("BluetoothFavorite") provideBluetoothFavoriteContactListLiveData( BluetoothFavoriteContactsLiveData.Factory bluetoothFavoriteContactsLiveDataFactory)97 static LiveData<List<Contact>> provideBluetoothFavoriteContactListLiveData( 98 BluetoothFavoriteContactsLiveData.Factory bluetoothFavoriteContactsLiveDataFactory) { 99 return bluetoothFavoriteContactsLiveDataFactory.create(null); 100 } 101 102 @Provides 103 @Named("LocalFavorite") provideLocalFavoriteContactListLiveData( FavoriteNumberRepository favoriteNumberRepository)104 static LiveData<List<Contact>> provideLocalFavoriteContactListLiveData( 105 FavoriteNumberRepository favoriteNumberRepository) { 106 return favoriteNumberRepository.getFavoriteContacts(null); 107 } 108 } 109