Use dagger in sample tuners.
PiperOrigin-RevId: 226771537
Change-Id: I65c74b00493da037cdbb648b1f7720cbc93bc8d3
diff --git a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
index 4f2f665..336c2c9 100644
--- a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
+++ b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTuner.java
@@ -16,6 +16,7 @@
package com.android.tv.tuner.sample.dvb.app;
+import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -27,15 +28,23 @@
import com.android.tv.common.flags.impl.DefaultExoplayer2Flags;
import com.android.tv.common.singletons.HasSingletons;
import com.android.tv.common.util.CommonUtils;
+import com.android.tv.tuner.modules.TunerSingletonsModule;
import com.android.tv.tuner.sample.dvb.singletons.SampleDvbSingletons;
import com.android.tv.tuner.sample.dvb.tvinput.SampleDvbTunerTvInputService;
import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
import com.android.tv.tuner.tvinput.factory.TunerSessionFactory;
import com.android.tv.tuner.tvinput.factory.TunerSessionFactoryImpl;
+import dagger.android.AndroidInjector;
+import dagger.android.DispatchingAndroidInjector;
+import dagger.android.HasActivityInjector;
+import javax.inject.Inject;
/** The top level application for Sample DVB Tuner. */
public class SampleDvbTuner extends BaseApplication
- implements SampleDvbSingletons, HasSingletons<SampleDvbSingletons> {
+ implements SampleDvbSingletons, HasSingletons<SampleDvbSingletons>, HasActivityInjector {
+
+ @Inject DispatchingAndroidInjector<Activity> mDispatchingActivityInjector;
+
private String mEmbeddedInputId;
private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
private final DefaultConcurrentDvrPlaybackFlags mConcurrentDvrPlaybackFlags =
@@ -45,6 +54,15 @@
new TunerSessionFactoryImpl(mExoplayer2Flags, mConcurrentDvrPlaybackFlags);
@Override
+ public void onCreate() {
+ super.onCreate();
+ DaggerSampleDvbTunerComponent.builder()
+ .tunerSingletonsModule(new TunerSingletonsModule(this))
+ .build()
+ .inject(this);
+ }
+
+ @Override
public Intent getTunerSetupIntent(Context context) {
// Make an intent to launch the setup activity of TV tuner input.
Intent intent =
@@ -88,4 +106,9 @@
public TunerSessionFactory getTunerSessionFactory() {
return mTunerSessionFactory;
}
+
+ @Override
+ public AndroidInjector<Activity> activityInjector() {
+ return mDispatchingActivityInjector;
+ }
}
diff --git a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerComponent.java b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerComponent.java
new file mode 100644
index 0000000..cb529ce
--- /dev/null
+++ b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerComponent.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.tuner.sample.dvb.app;
+
+import dagger.Component;
+import dagger.android.AndroidInjectionModule;
+import dagger.android.AndroidInjector;
+
+/** Dagger component for {@link SampleDvbTuner}. */
+@Component(modules = {AndroidInjectionModule.class, SampleDvbTunerModule.class})
+public interface SampleDvbTunerComponent extends AndroidInjector<SampleDvbTuner> {}
diff --git a/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerModule.java b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerModule.java
new file mode 100644
index 0000000..7297ff2
--- /dev/null
+++ b/tuner/SampleDvbTuner/src/com/android/tv/tuner/sample/dvb/app/SampleDvbTunerModule.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.tuner.sample.dvb.app;
+
+import com.android.tv.tuner.modules.TunerModule;
+import dagger.Module;
+
+/** Dagger module for {@link SampleDvbTuner}. */
+@Module(includes = {TunerModule.class})
+class SampleDvbTunerModule {}
diff --git a/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTuner.java b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTuner.java
index 82b40ff..a35530c 100644
--- a/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTuner.java
+++ b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTuner.java
@@ -16,6 +16,7 @@
package com.android.tv.tuner.sample.network.app;
+import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -27,15 +28,25 @@
import com.android.tv.common.flags.impl.DefaultExoplayer2Flags;
import com.android.tv.common.singletons.HasSingletons;
import com.android.tv.common.util.CommonUtils;
+import com.android.tv.tuner.modules.TunerSingletonsModule;
import com.android.tv.tuner.sample.network.singletons.SampleNetworkSingletons;
import com.android.tv.tuner.sample.network.tvinput.SampleNetworkTunerTvInputService;
import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
import com.android.tv.tuner.tvinput.factory.TunerSessionFactory;
import com.android.tv.tuner.tvinput.factory.TunerSessionFactoryImpl;
+import dagger.android.AndroidInjector;
+import dagger.android.DispatchingAndroidInjector;
+import dagger.android.HasActivityInjector;
+import javax.inject.Inject;
/** The top level application for Sample DVB Tuner. */
public class SampleNetworkTuner extends BaseApplication
- implements SampleNetworkSingletons, HasSingletons<SampleNetworkSingletons> {
+ implements SampleNetworkSingletons,
+ HasSingletons<SampleNetworkSingletons>,
+ HasActivityInjector {
+
+ @Inject DispatchingAndroidInjector<Activity> mDispatchingActivityInjector;
+
private String mEmbeddedInputId;
private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
private final DefaultConcurrentDvrPlaybackFlags mConcurrentDvrPlaybackFlags =
@@ -45,6 +56,15 @@
new TunerSessionFactoryImpl(mExoplayer2Flags, mConcurrentDvrPlaybackFlags);
@Override
+ public void onCreate() {
+ super.onCreate();
+ DaggerSampleNetworkTunerComponent.builder()
+ .tunerSingletonsModule(new TunerSingletonsModule(this))
+ .build()
+ .inject(this);
+ }
+
+ @Override
public Intent getTunerSetupIntent(Context context) {
// Make an intent to launch the setup activity of TV tuner input.
Intent intent =
@@ -88,4 +108,9 @@
public TunerSessionFactory getTunerSessionFactory() {
return mTunerSessionFactory;
}
+
+ @Override
+ public AndroidInjector<Activity> activityInjector() {
+ return mDispatchingActivityInjector;
+ }
}
diff --git a/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerComponent.java b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerComponent.java
new file mode 100644
index 0000000..71a20be
--- /dev/null
+++ b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerComponent.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.tuner.sample.network.app;
+
+import dagger.Component;
+import dagger.android.AndroidInjectionModule;
+import dagger.android.AndroidInjector;
+
+/** Dagger component for {@link SampleNetworkTuner}. */
+@Component(modules = {AndroidInjectionModule.class, SampleNetworkTunerModule.class})
+public interface SampleNetworkTunerComponent extends AndroidInjector<SampleNetworkTuner> {}
diff --git a/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerModule.java b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerModule.java
new file mode 100644
index 0000000..57e4ee6
--- /dev/null
+++ b/tuner/SampleNetworkTuner/src/com/android/tv/tuner/sample/network/app/SampleNetworkTunerModule.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.tuner.sample.network.app;
+
+import com.android.tv.tuner.modules.TunerModule;
+import dagger.Module;
+
+/** Dagger module for {@link SampleNetworkTuner}. */
+@Module(includes = {TunerModule.class})
+class SampleNetworkTunerModule {}
diff --git a/tuner/src/com/android/tv/tuner/modules/TunerModule.java b/tuner/src/com/android/tv/tuner/modules/TunerModule.java
new file mode 100644
index 0000000..b0b58e8
--- /dev/null
+++ b/tuner/src/com/android/tv/tuner/modules/TunerModule.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.tv.tuner.modules;
+
+import dagger.Module;
+
+/** Dagger module for TV Tuners. */
+@Module(includes = {TunerSingletonsModule.class})
+public class TunerModule {}
diff --git a/tuner/src/com/android/tv/tuner/modules/TunerSingletonsModule.java b/tuner/src/com/android/tv/tuner/modules/TunerSingletonsModule.java
new file mode 100644
index 0000000..b7fba8d
--- /dev/null
+++ b/tuner/src/com/android/tv/tuner/modules/TunerSingletonsModule.java
@@ -0,0 +1,18 @@
+package com.android.tv.tuner.modules;
+
+import com.android.tv.tuner.singletons.TunerSingletons;
+import dagger.Module;
+
+/**
+ * Provides bindings for items provided by {@link TunerSingletons}.
+ *
+ * <p>Use this module to inject items directly instead of using {@code TunerSingletons}.
+ */
+@Module
+public class TunerSingletonsModule {
+ private final TunerSingletons mTunerSingletons;
+
+ public TunerSingletonsModule(TunerSingletons tunerSingletons) {
+ this.mTunerSingletons = tunerSingletons;
+ }
+}