1 /* 2 * Copyright (C) 2018 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 package com.android.tv.modules; 17 18 import android.content.Context; 19 20 import com.android.tv.MainActivity; 21 import com.android.tv.SetupPassthroughActivity; 22 import com.android.tv.TvApplication; 23 import com.android.tv.common.buildtype.BuildTypeModule; 24 import com.android.tv.common.concurrent.NamedThreadFactory; 25 import com.android.tv.common.dagger.ApplicationModule; 26 import com.android.tv.common.dagger.annotations.ApplicationContext; 27 import com.android.tv.data.ChannelDataManager; 28 import com.android.tv.data.ChannelDataManagerFactory; 29 import com.android.tv.data.epg.EpgFetchService; 30 import com.android.tv.data.epg.EpgFetcher; 31 import com.android.tv.data.epg.EpgFetcherImpl; 32 import com.android.tv.dialog.PinDialogFragment; 33 import com.android.tv.dvr.DvrDataManager; 34 import com.android.tv.dvr.DvrDataManagerImpl; 35 import com.android.tv.dvr.DvrManager; 36 import com.android.tv.dvr.WritableDvrDataManager; 37 import com.android.tv.dvr.provider.DvrDbFuture.DvrQueryScheduleFuture; 38 import com.android.tv.dvr.provider.DvrDbSync; 39 import com.android.tv.dvr.provider.DvrDbSyncFactory; 40 import com.android.tv.dvr.provider.DvrQueryScheduleFutureFactory; 41 import com.android.tv.dvr.ui.playback.DvrPlaybackActivity; 42 import com.android.tv.menu.MenuRowFactory; 43 import com.android.tv.menu.MenuRowFactoryFactory; 44 import com.android.tv.menu.TvOptionsRowAdapter; 45 import com.android.tv.menu.TvOptionsRowAdapterFactory; 46 import com.android.tv.onboarding.OnboardingActivity; 47 import com.android.tv.onboarding.SetupSourcesFragment; 48 import com.android.tv.setup.SystemSetupActivity; 49 import com.android.tv.ui.DetailsActivity; 50 import com.android.tv.util.AsyncDbTask; 51 import com.android.tv.util.TvInputManagerHelper; 52 53 import dagger.Binds; 54 import dagger.Module; 55 import dagger.Provides; 56 import dagger.android.ContributesAndroidInjector; 57 58 import com.android.tv.common.flags.LegacyFlags; 59 60 import java.util.concurrent.Executor; 61 import java.util.concurrent.Executors; 62 63 import javax.inject.Singleton; 64 65 /** Dagger module for {@link TvApplication}. */ 66 @Module( 67 includes = { 68 ApplicationModule.class, 69 BuildTypeModule.class, 70 DetailsActivity.Module.class, 71 DvrPlaybackActivity.Module.class, 72 MainActivity.Module.class, 73 OnboardingActivity.Module.class, 74 SetupPassthroughActivity.Module.class, 75 SetupSourcesFragment.ContentFragment.Module.class, 76 SystemSetupActivity.Module.class, 77 TvSingletonsModule.class, 78 }) 79 public abstract class TvApplicationModule { 80 private static final NamedThreadFactory THREAD_FACTORY = new NamedThreadFactory("tv-app-db"); 81 82 @Provides 83 @AsyncDbTask.DbExecutor 84 @Singleton providesDbExecutor()85 static Executor providesDbExecutor() { 86 return Executors.newSingleThreadExecutor(THREAD_FACTORY); 87 } 88 89 @Provides 90 @Singleton providesTvInputManagerHelper( @pplicationContext Context context, LegacyFlags legacyFlags)91 static TvInputManagerHelper providesTvInputManagerHelper( 92 @ApplicationContext Context context, LegacyFlags legacyFlags) { 93 TvInputManagerHelper tvInputManagerHelper = new TvInputManagerHelper(context, legacyFlags); 94 tvInputManagerHelper.start(); 95 // Since this is injected as a Lazy in the application start is delayed. 96 return tvInputManagerHelper; 97 } 98 99 @Provides 100 @Singleton providesChannelDataManager(ChannelDataManagerFactory factory)101 static ChannelDataManager providesChannelDataManager(ChannelDataManagerFactory factory) { 102 ChannelDataManager channelDataManager = factory.create(); 103 channelDataManager.start(); 104 // Since this is injected as a Lazy in the application start is delayed. 105 return channelDataManager; 106 } 107 108 @Provides 109 @Singleton providesDvrManager(@pplicationContext Context context)110 static DvrManager providesDvrManager(@ApplicationContext Context context) { 111 return new DvrManager(context); 112 } 113 114 @Binds 115 @Singleton providesDvrDataManager(DvrDataManagerImpl impl)116 abstract DvrDataManager providesDvrDataManager(DvrDataManagerImpl impl); 117 118 @Binds 119 @Singleton providesWritableDvrDataManager(DvrDataManagerImpl impl)120 abstract WritableDvrDataManager providesWritableDvrDataManager(DvrDataManagerImpl impl); 121 122 @Binds 123 @Singleton epgFetcher(EpgFetcherImpl impl)124 abstract EpgFetcher epgFetcher(EpgFetcherImpl impl); 125 126 @Binds dvrDbSyncFactory(DvrDbSyncFactory dvrDbSyncFactory)127 abstract DvrDbSync.Factory dvrDbSyncFactory(DvrDbSyncFactory dvrDbSyncFactory); 128 129 @Binds dvrQueryScheduleFutureFactory( DvrQueryScheduleFutureFactory dvrQueryScheduleFutureFactory)130 abstract DvrQueryScheduleFuture.Factory dvrQueryScheduleFutureFactory( 131 DvrQueryScheduleFutureFactory dvrQueryScheduleFutureFactory); 132 133 @Binds tvOptionsRowAdapterFactory( TvOptionsRowAdapterFactory impl)134 abstract TvOptionsRowAdapter.Factory tvOptionsRowAdapterFactory( 135 TvOptionsRowAdapterFactory impl); 136 137 @Binds menuRowFactoryFactory(MenuRowFactoryFactory impl)138 abstract MenuRowFactory.Factory menuRowFactoryFactory(MenuRowFactoryFactory impl); 139 140 @ContributesAndroidInjector contributesPinDialogFragment()141 abstract PinDialogFragment contributesPinDialogFragment(); 142 143 @ContributesAndroidInjector contributesEpgFetchService()144 abstract EpgFetchService contributesEpgFetchService(); 145 } 146