Home | History | Annotate | Download | only in concurrent
      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.google.common.util.concurrent.ListeningExecutorService;
     27 import dagger.Subcomponent;
     28 import java.util.concurrent.ExecutorService;
     29 
     30 /** Dagger component which provides a {@link DialerExecutorFactory}. */
     31 @Subcomponent
     32 public abstract class DialerExecutorComponent {
     33 
     34   public abstract DialerExecutorFactory dialerExecutorFactory();
     35 
     36   @NonUiParallel
     37   public abstract ExecutorService lowPriorityThreadPool();
     38 
     39   @Ui
     40   public abstract ListeningExecutorService uiExecutor();
     41 
     42   @BackgroundExecutor
     43   public abstract ListeningExecutorService backgroundExecutor();
     44 
     45   @LightweightExecutor
     46   public abstract ListeningExecutorService lightweightExecutor();
     47 
     48   public <OutputT> UiListener<OutputT> createUiListener(
     49       FragmentManager fragmentManager, String taskId) {
     50     return UiListener.create(fragmentManager, taskId);
     51   }
     52 
     53   public static DialerExecutorComponent get(Context context) {
     54     return ((DialerExecutorComponent.HasComponent)
     55             ((HasRootComponent) context.getApplicationContext()).component())
     56         .dialerExecutorComponent();
     57   }
     58 
     59   /** Used to refer to the root application component. */
     60   public interface HasComponent {
     61     DialerExecutorComponent dialerExecutorComponent();
     62   }
     63 }
     64