Create ApplicationModule to provide Context and other android standard singletons.

PiperOrigin-RevId: 227587346
Change-Id: I9a7029dc0d291a6cab694b7ed15617dee468cda3
diff --git a/common/src/com/android/tv/common/dagger/ApplicationModule.java b/common/src/com/android/tv/common/dagger/ApplicationModule.java
new file mode 100644
index 0000000..592717b
--- /dev/null
+++ b/common/src/com/android/tv/common/dagger/ApplicationModule.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2019 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.common.dagger;
+
+import android.app.Application;
+import android.content.Context;
+import android.os.Looper;
+import com.android.tv.common.dagger.annotations.ApplicationContext;
+import com.android.tv.common.dagger.annotations.MainLooper;
+import dagger.Module;
+import dagger.Provides;
+
+/**
+ * Provides application-scope qualifiers for the {@link Application}, the application context, and
+ * the application's main looper.
+ */
+@Module
+public final class ApplicationModule {
+    private final Application application;
+
+    public ApplicationModule(Application application) {
+        this.application = application;
+    }
+
+    @Provides
+    Application provideApplication() {
+        return application;
+    }
+
+    @Provides
+    @ApplicationContext
+    Context provideContext() {
+        return application.getApplicationContext();
+    }
+
+    @Provides
+    @MainLooper
+    static Looper provideMainLooper() {
+        return Looper.getMainLooper();
+    }
+}
diff --git a/common/src/com/android/tv/common/dagger/annotations/ApplicationContext.java b/common/src/com/android/tv/common/dagger/annotations/ApplicationContext.java
new file mode 100644
index 0000000..8631815
--- /dev/null
+++ b/common/src/com/android/tv/common/dagger/annotations/ApplicationContext.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2019 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.common.dagger.annotations;
+
+import javax.inject.Qualifier;
+
+/** Annotation for requesting the application's context. */
+@Qualifier
+public @interface ApplicationContext {}
diff --git a/common/src/com/android/tv/common/dagger/annotations/MainLooper.java b/common/src/com/android/tv/common/dagger/annotations/MainLooper.java
new file mode 100644
index 0000000..a8b4100
--- /dev/null
+++ b/common/src/com/android/tv/common/dagger/annotations/MainLooper.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2019 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.common.dagger.annotations;
+
+import javax.inject.Qualifier;
+
+/** Annotation for requesting a Looper that is on the UI thread. */
+@Qualifier
+public @interface MainLooper {}
diff --git a/src/com/android/tv/modules/TvApplicationModule.java b/src/com/android/tv/modules/TvApplicationModule.java
index 48e7fe7..a252723 100644
--- a/src/com/android/tv/modules/TvApplicationModule.java
+++ b/src/com/android/tv/modules/TvApplicationModule.java
@@ -17,10 +17,16 @@
 
 import com.android.tv.MainActivity;
 import com.android.tv.TvApplication;
+import com.android.tv.common.dagger.ApplicationModule;
 import com.android.tv.onboarding.OnboardingActivity;
 import dagger.Module;
 
 /** Dagger module for {@link TvApplication}. */
-@Module(includes = {
-        TvSingletonsModule.class, MainActivity.Module.class, OnboardingActivity.Module.class})
+@Module(
+        includes = {
+            ApplicationModule.class,
+            TvSingletonsModule.class,
+            MainActivity.Module.class,
+            OnboardingActivity.Module.class
+        })
 public class TvApplicationModule {}