• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.common.concurrent;
18 
19 import android.app.FragmentManager;
20 import android.content.Context;
21 import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor;
22 import com.android.dialer.common.concurrent.Annotations.LightweightExecutor;
23 import com.android.dialer.common.concurrent.Annotations.NonUiParallel;
24 import com.android.dialer.common.concurrent.Annotations.Ui;
25 import com.android.dialer.inject.HasRootComponent;
26 import com.android.dialer.inject.IncludeInDialerRoot;
27 import com.google.common.util.concurrent.ListeningExecutorService;
28 import dagger.Subcomponent;
29 import java.util.concurrent.ExecutorService;
30 
31 /** Dagger component which provides a {@link DialerExecutorFactory}. */
32 @Subcomponent
33 public abstract class DialerExecutorComponent {
34 
dialerExecutorFactory()35   public abstract DialerExecutorFactory dialerExecutorFactory();
36 
37   @NonUiParallel
lowPriorityThreadPool()38   public abstract ExecutorService lowPriorityThreadPool();
39 
40   @Ui
uiExecutor()41   public abstract ListeningExecutorService uiExecutor();
42 
43   @BackgroundExecutor
backgroundExecutor()44   public abstract ListeningExecutorService backgroundExecutor();
45 
46   @LightweightExecutor
lightweightExecutor()47   public abstract ListeningExecutorService lightweightExecutor();
48 
createUiListener( FragmentManager fragmentManager, String taskId)49   public <OutputT> UiListener<OutputT> createUiListener(
50       FragmentManager fragmentManager, String taskId) {
51     return UiListener.create(fragmentManager, taskId);
52   }
53 
54   /**
55    * Version of {@link #createUiListener(FragmentManager, String)} that accepts support fragment
56    * manager.
57    */
createUiListener( android.support.v4.app.FragmentManager fragmentManager, String taskId)58   public <OutputT> SupportUiListener<OutputT> createUiListener(
59       android.support.v4.app.FragmentManager fragmentManager, String taskId) {
60     return SupportUiListener.create(fragmentManager, taskId);
61   }
62 
get(Context context)63   public static DialerExecutorComponent get(Context context) {
64     return ((DialerExecutorComponent.HasComponent)
65             ((HasRootComponent) context.getApplicationContext()).component())
66         .dialerExecutorComponent();
67   }
68 
69   /** Used to refer to the root application component. */
70   @IncludeInDialerRoot
71   public interface HasComponent {
dialerExecutorComponent()72     DialerExecutorComponent dialerExecutorComponent();
73   }
74 }
75