1ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian/*
2ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * Copyright (C) 2011 The Android Open Source Project
3ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
4ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * Licensed under the Apache License, Version 2.0 (the "License");
5ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * you may not use this file except in compliance with the License.
6ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * You may obtain a copy of the License at
7ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
8ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *      http://www.apache.org/licenses/LICENSE-2.0
9ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
10ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * Unless required by applicable law or agreed to in writing, software
11ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * distributed under the License is distributed on an "AS IS" BASIS,
12ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * See the License for the specific language governing permissions and
14ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * limitations under the License.
15ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian */
16ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian
179779f967ebb9512e5b19090b071572c9c4f0f2a6Eric Erfanianpackage com.android.dialer.common.concurrent;
18ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian
19ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanianimport android.os.AsyncTask;
20ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanianimport android.support.annotation.MainThread;
21ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanianimport java.util.concurrent.Executor;
22ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian
23ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian/**
24ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * Interface used to submit {@link AsyncTask} objects to run in the background.
25ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
26ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * <p>This interface has a direct parallel with the {@link Executor} interface. It exists to
27ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * decouple the mechanics of AsyncTask submission from the description of how that AsyncTask will
28ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * execute.
29ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
30ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * <p>One immediate benefit of this approach is that testing becomes much easier, since it is easy
31ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * to introduce a mock or fake AsyncTaskExecutor in unit/integration tests, and thus inspect which
32ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * tasks have been submitted and control their execution in an orderly manner.
33ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian *
34ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * <p>Another benefit in due course will be the management of the submitted tasks. An extension to
35ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * this interface is planned to allow Activities to easily cancel all the submitted tasks that are
36ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian * still pending in the onDestroy() method of the Activity.
37ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian */
38ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanianpublic interface AsyncTaskExecutor {
39ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian
40ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian  /**
41ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   * Executes the given AsyncTask with the default Executor.
42ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   *
43ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   * <p>This method <b>must only be called from the ui thread</b>.
44ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   *
45ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   * <p>The identifier supplied is any Object that can be used to identify the task later. Most
46ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   * commonly this will be an enum which the tests can also refer to. {@code null} is also accepted,
47ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   * though of course this won't help in identifying the task later.
48ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian   */
49ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian  @MainThread
50ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian  <T> AsyncTask<T, ?, ?> submit(Object identifier, AsyncTask<T, ?, ?> task, T... params);
51ccca31529c07970e89419fb85a9e8153a5396838Eric Erfanian}
52