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 17 package com.android.dialer.inject.demo; 18 19 import android.app.Application; 20 import android.support.annotation.NonNull; 21 import com.android.dialer.inject.ContextModule; 22 import com.android.dialer.inject.DialerRootComponent; 23 import com.android.dialer.inject.DialerVariant; 24 import com.android.dialer.inject.HasRootComponent; 25 26 /** Demo dialer dagger application. */ 27 @DialerRootComponent(variant = DialerVariant.DIALER_DEMO) 28 public final class DemoDaggerApplication extends Application implements HasRootComponent { 29 30 private volatile Object rootComponent; 31 32 /** Returns a cached instance of application's root component. */ 33 @Override 34 @NonNull component()35 public final Object component() { 36 Object result = rootComponent; 37 if (result == null) { 38 synchronized (this) { 39 result = rootComponent; 40 if (result == null) { 41 rootComponent = 42 result = DaggerDialerDemo.builder().contextModule(new ContextModule(this)).build(); 43 } 44 } 45 } 46 return result; 47 } 48 49 @Override onCreate()50 public void onCreate() { 51 super.onCreate(); 52 53 DemoSubcomponent.get(this).demoObjects(); 54 } 55 } 56