1 /* 2 * Copyright (C) 2023 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.intentresolver.icons 18 19 import android.app.ActivityManager 20 import android.content.Context 21 import android.content.pm.PackageManager 22 import com.android.intentresolver.SimpleIconFactory 23 import com.android.intentresolver.TargetPresentationGetter 24 import dagger.Module 25 import dagger.Provides 26 import dagger.hilt.InstallIn 27 import dagger.hilt.android.components.ActivityComponent 28 import dagger.hilt.android.qualifiers.ActivityContext 29 import dagger.hilt.android.scopes.ActivityScoped 30 import javax.inject.Provider 31 32 @Module 33 @InstallIn(ActivityComponent::class) 34 object TargetDataLoaderModule { 35 @Provides simpleIconFactorynull36 fun simpleIconFactory(@ActivityContext context: Context): SimpleIconFactory = 37 SimpleIconFactory.obtain(context) 38 39 @Provides 40 fun presentationGetterFactory( 41 iconFactoryProvider: Provider<SimpleIconFactory>, 42 packageManager: PackageManager, 43 activityManager: ActivityManager, 44 ): TargetPresentationGetter.Factory = 45 TargetPresentationGetter.Factory( 46 iconFactoryProvider, 47 packageManager, 48 activityManager.launcherLargeIconDensity, 49 ) 50 51 @Provides 52 @ActivityScoped 53 @Caching 54 fun cachingTargetDataLoader( 55 @ActivityContext context: Context, 56 dataLoaderFactory: DefaultTargetDataLoader.Factory, 57 ): TargetDataLoader = 58 // Intended to be used in Chooser only thus the hardcoded isAudioCaptureDevice value. 59 CachingTargetDataLoader(context, dataLoaderFactory.create(isAudioCaptureDevice = false)) 60 } 61