diff options
author | Eric Erfanian <erfanian@google.com> | 2017-08-31 06:57:16 -0700 |
---|---|---|
committer | Roland Levillain <rpl@google.com> | 2017-09-04 18:05:19 +0100 |
commit | fc0eb8ccebcc7846db5e8b5c5430070055679bfa (patch) | |
tree | a8a23c3202e4161ffd57a71095a404db1bcf5735 /java/com/android/dialer/common/concurrent | |
parent | ea7b4dc89590ffa3332766a531e0eab6ffb9aebd (diff) |
Update Dialer source to latest internal Google revision.
Previously, Android's Dialer app was developed in an internal Google
source control system and only exported to public during AOSP drops.
The Dialer team is now switching to a public development model similar
to the telephony team.
This CL represents all internal Google changes that were committed to
Dialer between the public O release and today's tip of tree on internal
master. This CL squashes those changes into a single commit.
In subsequent changes, changes will be exported on a per-commit basis.
(cherry picked from commit 2ca4318cc1ee57dda907ba2069bd61d162b1baef
and amended to match paths of dependencies under
prebuilts/maven_repo/bumptech/com/github/bumptech/glide/.)
This CL was generated using these commands from a repository at
stage-stage-master at revision ea7b4dc89590ffa3332766a531e0eab6ffb9aebd
("Merge "Update Dialer source to latest internal Google revision." am: c39ea3c55f -s ours"):
git diff --binary 2ca4318cc1ee57dda907ba2069bd61d162b1baef | git apply -R --index
git commit -c 2ca4318cc1ee57dda907ba2069bd61d162b1baef
Test: make, flash install, run
Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8
PiperOrigin-RevId: 167068436
Diffstat (limited to 'java/com/android/dialer/common/concurrent')
4 files changed, 57 insertions, 14 deletions
diff --git a/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java b/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java index 82e517d9a..a87bbceb4 100644 --- a/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java +++ b/java/com/android/dialer/common/concurrent/DefaultDialerExecutorFactory.java @@ -166,17 +166,7 @@ public class DefaultDialerExecutorFactory implements DialerExecutorFactory { }); private static final Executor defaultParallelExecutor = - Executors.newFixedThreadPool( - 5, - new ThreadFactory() { - @Override - public Thread newThread(Runnable runnable) { - LogUtil.i("NonUiTaskBuilder.newThread", "creating parallel thread"); - Thread thread = new Thread(runnable, "NonUiTaskBuilder-Parallel"); - thread.setPriority(4); // Corresponds to Process.THREAD_PRIORITY_BACKGROUND - return thread; - } - }); + DialerExecutors.getLowPriorityThreadPool(); NonUiTaskBuilder(Worker<InputT, OutputT> worker) { this(worker, defaultSerialExecutorService, defaultParallelExecutor); diff --git a/java/com/android/dialer/common/concurrent/DialerExecutors.java b/java/com/android/dialer/common/concurrent/DialerExecutors.java index 148d8660c..81b3c5cb3 100644 --- a/java/com/android/dialer/common/concurrent/DialerExecutors.java +++ b/java/com/android/dialer/common/concurrent/DialerExecutors.java @@ -19,7 +19,11 @@ package com.android.dialer.common.concurrent; import android.app.FragmentManager; import android.support.annotation.NonNull; import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; /** * Factory methods for creating {@link DialerExecutor} objects for doing background work. @@ -131,4 +135,27 @@ public final class DialerExecutors { @NonNull Worker<InputT, OutputT> worker) { return new DefaultDialerExecutorFactory().createNonUiTaskBuilder(Assert.isNotNull(worker)); } + + private static final Executor lowPriorityThreadPool = + Executors.newFixedThreadPool( + 5, + new ThreadFactory() { + @Override + public Thread newThread(Runnable runnable) { + LogUtil.i("DialerExecutors.newThread", "creating low priority thread"); + Thread thread = new Thread(runnable, "DialerExecutors-LowPriority"); + thread.setPriority(4); // Corresponds to Process.THREAD_PRIORITY_BACKGROUND + return thread; + } + }); + + /** + * An application-wide thread pool used for low priority (non-UI) tasks. + * + * <p>This exists to prevent each individual dialer component from having to create its own + * threads/pools, which would result in the application having more threads than really necessary. + */ + public static Executor getLowPriorityThreadPool() { + return lowPriorityThreadPool; + } } diff --git a/java/com/android/dialer/common/concurrent/DialerUiTaskFragment.java b/java/com/android/dialer/common/concurrent/DialerUiTaskFragment.java index 7f2a5a06b..f0b753758 100644 --- a/java/com/android/dialer/common/concurrent/DialerUiTaskFragment.java +++ b/java/com/android/dialer/common/concurrent/DialerUiTaskFragment.java @@ -88,7 +88,7 @@ public final class DialerUiTaskFragment<InputT, OutputT> extends Fragment { (DialerUiTaskFragment<InputT, OutputT>) fragmentManager.findFragmentByTag(taskId); if (fragment == null) { - LogUtil.i("DialerUiTaskFragment.create", "creating new DialerUiTaskFragment"); + LogUtil.i("DialerUiTaskFragment.create", "creating new DialerUiTaskFragment for " + taskId); fragment = new DialerUiTaskFragment<>(); fragmentManager.beginTransaction().add(fragment, taskId).commit(); } @@ -146,14 +146,38 @@ public final class DialerUiTaskFragment<InputT, OutputT> extends Fragment { if (successListener == null) { LogUtil.i("DialerUiTaskFragment.runTask", "task succeeded but UI is dead"); } else { - ThreadUtil.postOnUiThread(() -> successListener.onSuccess(output)); + ThreadUtil.postOnUiThread( + () -> { + // Even though there is a null check above, it is possible for the activity/fragment + // to be finished between the time the runnable is posted and the time it executes. Do + // an additional check here. + if (successListener == null) { + LogUtil.i( + "DialerUiTaskFragment.runTask", + "task succeeded but UI died after success runnable posted"); + } else { + successListener.onSuccess(output); + } + }); } } catch (Throwable throwable) { LogUtil.e("DialerUiTaskFragment.runTask", "task failed", throwable); if (failureListener == null) { LogUtil.i("DialerUiTaskFragment.runTask", "task failed but UI is dead"); } else { - ThreadUtil.postOnUiThread(() -> failureListener.onFailure(throwable)); + ThreadUtil.postOnUiThread( + () -> { + // Even though there is a null check above, it is possible for the activity/fragment + // to be finished between the time the runnable is posted and the time it executes. Do + // an additional check here. + if (failureListener == null) { + LogUtil.i( + "DialerUiTaskFragment.runTask", + "task failed but UI died after failure runnable posted"); + } else { + failureListener.onFailure(throwable); + } + }); } } } diff --git a/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java b/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java index 6d02fe67f..c7a7f36a6 100644 --- a/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java +++ b/java/com/android/dialer/common/concurrent/FallibleAsyncTask.java @@ -30,7 +30,9 @@ import com.google.auto.value.AutoValue; * @param <ParamsT> the type of the parameters sent to the task upon execution * @param <ProgressT> the type of the progress units published during the background computation * @param <ResultT> the type of the result of the background computation + * @deprecated Please use {@link DialerExecutors}. */ +@Deprecated public abstract class FallibleAsyncTask<ParamsT, ProgressT, ResultT> extends AsyncTask<ParamsT, ProgressT, FallibleTaskResult<ResultT>> { |