diff options
-rw-r--r-- | Android.mk | 15 | ||||
-rw-r--r-- | java/com/android/dialer/inject/ContextModule.java | 1 | ||||
-rw-r--r-- | java/com/android/dialer/inject/DialerRootComponent.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java) | 2 | ||||
-rw-r--r-- | java/com/android/dialer/inject/DialerVariant.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java) | 6 | ||||
-rw-r--r-- | java/com/android/dialer/inject/IncludeInDialerRoot.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java) | 2 | ||||
-rw-r--r-- | java/com/android/dialer/inject/InstallIn.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java) | 2 | ||||
-rw-r--r-- | java/com/android/dialer/inject/RootComponentGeneratorMetadata.java (renamed from java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java) | 2 | ||||
-rw-r--r-- | java/com/android/dialer/inject/demo/DemoDaggerApplication.java | 55 | ||||
-rw-r--r-- | java/com/android/dialer/inject/demo/DemoModule.java | 35 | ||||
-rw-r--r-- | java/com/android/dialer/inject/demo/DemoObject.java | 32 | ||||
-rw-r--r-- | java/com/android/dialer/inject/demo/DemoSubcomponent.java | 40 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/ComponentGeneratingStep.java (renamed from java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java) | 4 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/MetadataGeneratingStep.java (renamed from java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java) | 8 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java (renamed from java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java) | 12 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/RootComponentProcessor.java (renamed from java/com/android/dialer/rootcomponentgenerator/processor/RootComponentProcessor.java) | 2 | ||||
-rw-r--r-- | java/com/android/dialer/rootcomponentgenerator/RootComponentUtils.java (renamed from java/com/android/dialer/rootcomponentgenerator/processor/RootComponentUtils.java) | 2 |
16 files changed, 195 insertions, 25 deletions
diff --git a/Android.mk b/Android.mk index f142b653b..a1763860c 100644 --- a/Android.mk +++ b/Android.mk @@ -39,7 +39,8 @@ EXCLUDE_FILES += \ # Exclude rootcomponentgenerator EXCLUDE_FILES += \ - $(call all-java-files-under, $(BASE_DIR)/dialer/rootcomponentgenerator/processor) + $(call all-java-files-under, $(BASE_DIR)/dialer/rootcomponentgenerator) \ + $(call all-java-files-under, $(BASE_DIR)/dialer/inject/demo) # Exclude build variants for now EXCLUDE_FILES += \ @@ -154,7 +155,7 @@ LOCAL_ANNOTATION_PROCESSORS := \ dialer-rootcomponentprocessor LOCAL_ANNOTATION_PROCESSOR_CLASSES := \ - com.google.auto.value.processor.AutoValueProcessor,dagger.internal.codegen.ComponentProcessor,com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor,com.android.dialer.rootcomponentgenerator.processor.RootComponentProcessor + com.google.auto.value.processor.AutoValueProcessor,dagger.internal.codegen.ComponentProcessor,com.bumptech.glide.annotation.compiler.GlideAnnotationProcessor,com.android.dialer.rootcomponentgenerator.RootComponentProcessor # Begin Bug: 37077388 LOCAL_DX_FLAGS := --multi-dex @@ -436,9 +437,13 @@ LOCAL_IS_HOST_MODULE := true BASE_DIR := java/com/android LOCAL_SRC_FILES := \ - $(call all-java-files-under, $(BASE_DIR)/dialer/rootcomponentgenerator/annotation) \ - $(call all-java-files-under, $(BASE_DIR)/dialer/rootcomponentgenerator/processor) - + $(call all-java-files-under, $(BASE_DIR)/dialer/rootcomponentgenerator) \ + $(BASE_DIR)/dialer/inject/DialerRootComponent.java \ + $(BASE_DIR)/dialer/inject/DialerVariant.java \ + $(BASE_DIR)/dialer/inject/HasRootComponent.java \ + $(BASE_DIR)/dialer/inject/IncludeInDialerRoot.java \ + $(BASE_DIR)/dialer/inject/InstallIn.java \ + $(BASE_DIR)/dialer/inject/RootComponentGeneratorMetadata.java LOCAL_STATIC_JAVA_LIBRARIES := \ dialer-guava \ diff --git a/java/com/android/dialer/inject/ContextModule.java b/java/com/android/dialer/inject/ContextModule.java index e3da08edc..828f97830 100644 --- a/java/com/android/dialer/inject/ContextModule.java +++ b/java/com/android/dialer/inject/ContextModule.java @@ -24,6 +24,7 @@ import dagger.Provides; /** Provides the singleton application context object. */ @Module +@InstallIn(variants = {DialerVariant.DIALER_DEMO, DialerVariant.DIALER_TEST}) public final class ContextModule { @NonNull private final Context context; diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java b/java/com/android/dialer/inject/DialerRootComponent.java index b6bf22efb..11dbf962e 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerRootComponent.java +++ b/java/com/android/dialer/inject/DialerRootComponent.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.annotation; +package com.android.dialer.inject; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java b/java/com/android/dialer/inject/DialerVariant.java index 0bb185296..2e5794ffb 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/DialerVariant.java +++ b/java/com/android/dialer/inject/DialerVariant.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.annotation; +package com.android.dialer.inject; /** Represents all dialer variants. */ public enum DialerVariant { @@ -27,7 +27,9 @@ public enum DialerVariant { // TEST variant will be used in situations where we need create in-test application class which // doesn't belong to any variants listed above - DIALER_TEST("DialerTest"); + DIALER_TEST("DialerTest"), + // Just for sample code in inject/demo. + DIALER_DEMO("DialerDemo"); private final String variant; diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java b/java/com/android/dialer/inject/IncludeInDialerRoot.java index 4ce9ec3a3..4e800559a 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/IncludeInDialerRoot.java +++ b/java/com/android/dialer/inject/IncludeInDialerRoot.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.annotation; +package com.android.dialer.inject; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java b/java/com/android/dialer/inject/InstallIn.java index 01a7873b0..a6f973b7b 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/InstallIn.java +++ b/java/com/android/dialer/inject/InstallIn.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.annotation; +package com.android.dialer.inject; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java b/java/com/android/dialer/inject/RootComponentGeneratorMetadata.java index 070cc7350..51d134a95 100644 --- a/java/com/android/dialer/rootcomponentgenerator/annotation/RootComponentGeneratorMetadata.java +++ b/java/com/android/dialer/inject/RootComponentGeneratorMetadata.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.annotation; +package com.android.dialer.inject; import java.lang.annotation.ElementType; import java.lang.annotation.Target; diff --git a/java/com/android/dialer/inject/demo/DemoDaggerApplication.java b/java/com/android/dialer/inject/demo/DemoDaggerApplication.java new file mode 100644 index 000000000..0c13dbb48 --- /dev/null +++ b/java/com/android/dialer/inject/demo/DemoDaggerApplication.java @@ -0,0 +1,55 @@ +/* + * 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.dialer.inject.demo; + +import android.app.Application; +import android.support.annotation.NonNull; +import com.android.dialer.inject.ContextModule; +import com.android.dialer.inject.DialerRootComponent; +import com.android.dialer.inject.DialerVariant; +import com.android.dialer.inject.HasRootComponent; + +/** Demo dialer dagger application. */ +@DialerRootComponent(variant = DialerVariant.DIALER_DEMO) +public final class DemoDaggerApplication extends Application implements HasRootComponent { + + private volatile Object rootComponent; + + /** Returns a cached instance of application's root component. */ + @Override + @NonNull + public final Object component() { + Object result = rootComponent; + if (result == null) { + synchronized (this) { + result = rootComponent; + if (result == null) { + rootComponent = + result = DaggerDialerDemo.builder().contextModule(new ContextModule(this)).build(); + } + } + } + return result; + } + + @Override + public void onCreate() { + super.onCreate(); + + DemoSubcomponent.get(this).demoObject(); + } +} diff --git a/java/com/android/dialer/inject/demo/DemoModule.java b/java/com/android/dialer/inject/demo/DemoModule.java new file mode 100644 index 000000000..40cd6fea1 --- /dev/null +++ b/java/com/android/dialer/inject/demo/DemoModule.java @@ -0,0 +1,35 @@ +/* + * 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.dialer.inject.demo; + +import com.android.dialer.inject.DialerVariant; +import com.android.dialer.inject.InstallIn; +import dagger.Module; +import dagger.Provides; + +/** Module for demo dagger application. */ +@Module +@InstallIn(variants = DialerVariant.DIALER_DEMO) +public final class DemoModule { + + private DemoModule() {} + + @Provides + static DemoObject provide() { + return new DemoObject("prod"); + } +} diff --git a/java/com/android/dialer/inject/demo/DemoObject.java b/java/com/android/dialer/inject/demo/DemoObject.java new file mode 100644 index 000000000..c6d48a14d --- /dev/null +++ b/java/com/android/dialer/inject/demo/DemoObject.java @@ -0,0 +1,32 @@ +/* + * 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.dialer.inject.demo; + +/** Object used to demonstrate dagger bindings. */ +class DemoObject { + + private final String value; + + DemoObject(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } +} diff --git a/java/com/android/dialer/inject/demo/DemoSubcomponent.java b/java/com/android/dialer/inject/demo/DemoSubcomponent.java new file mode 100644 index 000000000..ff000aaa9 --- /dev/null +++ b/java/com/android/dialer/inject/demo/DemoSubcomponent.java @@ -0,0 +1,40 @@ +/* + * 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.dialer.inject.demo; + +import android.content.Context; +import com.android.dialer.inject.HasRootComponent; +import com.android.dialer.inject.IncludeInDialerRoot; +import dagger.Subcomponent; + +/** Subcomponent for the demo dagger application. */ +@Subcomponent +public abstract class DemoSubcomponent { + + abstract DemoObject demoObject(); + + public static DemoSubcomponent get(Context context) { + return ((HasComponent) ((HasRootComponent) context.getApplicationContext()).component()) + .demoSubcomponent(); + } + + /** Used to refer to the root application component. */ + @IncludeInDialerRoot + public interface HasComponent { + DemoSubcomponent demoSubcomponent(); + } +} diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/ComponentGeneratingStep.java index 04d42ac59..1a40611c5 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/ComponentGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/ComponentGeneratingStep.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.processor; +package com.android.dialer.rootcomponentgenerator; import static com.google.auto.common.AnnotationMirrors.getAnnotationValue; import static com.google.auto.common.MoreElements.getAnnotationMirror; @@ -23,7 +23,7 @@ import static javax.lang.model.element.Modifier.PUBLIC; import static javax.lang.model.element.Modifier.STATIC; import static javax.lang.model.util.ElementFilter.typesIn; -import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; +import com.android.dialer.inject.IncludeInDialerRoot; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; import com.google.auto.common.MoreElements; import com.google.common.base.Optional; diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/MetadataGeneratingStep.java index 3b46ed0d0..266574d76 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/MetadataGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/MetadataGeneratingStep.java @@ -14,13 +14,13 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.processor; +package com.android.dialer.rootcomponentgenerator; import static javax.tools.Diagnostic.Kind.ERROR; -import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; -import com.android.dialer.rootcomponentgenerator.annotation.InstallIn; -import com.android.dialer.rootcomponentgenerator.annotation.RootComponentGeneratorMetadata; +import com.android.dialer.inject.IncludeInDialerRoot; +import com.android.dialer.inject.InstallIn; +import com.android.dialer.inject.RootComponentGeneratorMetadata; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; import com.google.auto.common.MoreElements; import com.google.common.collect.ImmutableSet; diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java b/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java index ad91a3cbe..61c326a3c 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentGeneratingStep.java +++ b/java/com/android/dialer/rootcomponentgenerator/RootComponentGeneratingStep.java @@ -14,17 +14,17 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.processor; +package com.android.dialer.rootcomponentgenerator; import static com.google.auto.common.AnnotationMirrors.getAnnotationValue; import static com.google.auto.common.MoreElements.getAnnotationMirror; import static com.google.auto.common.MoreElements.isAnnotationPresent; -import com.android.dialer.rootcomponentgenerator.annotation.DialerRootComponent; -import com.android.dialer.rootcomponentgenerator.annotation.DialerVariant; -import com.android.dialer.rootcomponentgenerator.annotation.IncludeInDialerRoot; -import com.android.dialer.rootcomponentgenerator.annotation.InstallIn; -import com.android.dialer.rootcomponentgenerator.annotation.RootComponentGeneratorMetadata; +import com.android.dialer.inject.DialerRootComponent; +import com.android.dialer.inject.DialerVariant; +import com.android.dialer.inject.IncludeInDialerRoot; +import com.android.dialer.inject.InstallIn; +import com.android.dialer.inject.RootComponentGeneratorMetadata; import com.google.auto.common.BasicAnnotationProcessor.ProcessingStep; import com.google.auto.common.MoreElements; import com.google.common.base.Optional; diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentProcessor.java b/java/com/android/dialer/rootcomponentgenerator/RootComponentProcessor.java index 56caa9ea4..76df5e312 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentProcessor.java +++ b/java/com/android/dialer/rootcomponentgenerator/RootComponentProcessor.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.processor; +package com.android.dialer.rootcomponentgenerator; import com.google.auto.common.BasicAnnotationProcessor; import com.google.auto.service.AutoService; diff --git a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentUtils.java b/java/com/android/dialer/rootcomponentgenerator/RootComponentUtils.java index 889297154..cdcae9250 100644 --- a/java/com/android/dialer/rootcomponentgenerator/processor/RootComponentUtils.java +++ b/java/com/android/dialer/rootcomponentgenerator/RootComponentUtils.java @@ -14,7 +14,7 @@ * limitations under the License */ -package com.android.dialer.rootcomponentgenerator.processor; +package com.android.dialer.rootcomponentgenerator; import com.squareup.javapoet.JavaFile; import com.squareup.javapoet.TypeSpec; |