Loading core/java/android/os/AsyncTask.java +34 −6 Original line number Diff line number Diff line Loading @@ -17,14 +17,14 @@ package android.os; import android.annotation.MainThread; import android.annotation.Nullable; import android.annotation.WorkerThread; import java.util.ArrayDeque; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.FutureTask; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; Loading Loading @@ -232,6 +232,8 @@ public abstract class AsyncTask<Params, Progress, Result> { private final AtomicBoolean mCancelled = new AtomicBoolean(); private final AtomicBoolean mTaskInvoked = new AtomicBoolean(); private final Handler mHandler; private static class SerialExecutor implements Executor { final ArrayDeque<Runnable> mTasks = new ArrayDeque<Runnable>(); Runnable mActive; Loading Loading @@ -277,15 +279,19 @@ public abstract class AsyncTask<Params, Progress, Result> { FINISHED, } private static Handler getHandler() { private static Handler getMainHandler() { synchronized (AsyncTask.class) { if (sHandler == null) { sHandler = new InternalHandler(); sHandler = new InternalHandler(Looper.getMainLooper()); } return sHandler; } } private Handler getHandler() { return mHandler; } /** @hide */ public static void setDefaultExecutor(Executor exec) { sDefaultExecutor = exec; Loading @@ -295,6 +301,28 @@ public abstract class AsyncTask<Params, Progress, Result> { * Creates a new asynchronous task. This constructor must be invoked on the UI thread. */ public AsyncTask() { this((Looper) null); } /** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. * * @hide */ public AsyncTask(@Nullable Handler handler) { this(handler != null ? handler.getLooper() : null); } /** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. * * @hide */ public AsyncTask(@Nullable Looper callbackLooper) { mHandler = callbackLooper == null || callbackLooper == Looper.getMainLooper() ? getMainHandler() : new Handler(callbackLooper); mWorker = new WorkerRunnable<Params, Result>() { public Result call() throws Exception { mTaskInvoked.set(true); Loading Loading @@ -670,8 +698,8 @@ public abstract class AsyncTask<Params, Progress, Result> { } private static class InternalHandler extends Handler { public InternalHandler() { super(Looper.getMainLooper()); public InternalHandler(Looper looper) { super(looper); } @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"}) Loading core/java/android/widget/SelectionActionModeHelper.java +3 −1 Original line number Diff line number Diff line Loading @@ -74,8 +74,9 @@ final class SelectionActionModeHelper { startActionMode(null); } else { resetTextClassificationHelper(true /* resetSelectionTag */); final TextView tv = mEditor.getTextView(); mTextClassificationAsyncTask = new TextClassificationAsyncTask( mEditor.getTextView(), tv, TIMEOUT_DURATION, adjustSelection ? mTextClassificationHelper::suggestSelection Loading Loading @@ -340,6 +341,7 @@ final class SelectionActionModeHelper { @NonNull TextView textView, int timeOut, @NonNull Supplier<SelectionResult> selectionResultSupplier, @NonNull Consumer<SelectionResult> selectionResultCallback) { super(textView != null ? textView.getHandler() : null); mTextView = Preconditions.checkNotNull(textView); mTimeOutDuration = timeOut; mSelectionResultSupplier = Preconditions.checkNotNull(selectionResultSupplier); Loading Loading
core/java/android/os/AsyncTask.java +34 −6 Original line number Diff line number Diff line Loading @@ -17,14 +17,14 @@ package android.os; import android.annotation.MainThread; import android.annotation.Nullable; import android.annotation.WorkerThread; import java.util.ArrayDeque; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import java.util.concurrent.FutureTask; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; Loading Loading @@ -232,6 +232,8 @@ public abstract class AsyncTask<Params, Progress, Result> { private final AtomicBoolean mCancelled = new AtomicBoolean(); private final AtomicBoolean mTaskInvoked = new AtomicBoolean(); private final Handler mHandler; private static class SerialExecutor implements Executor { final ArrayDeque<Runnable> mTasks = new ArrayDeque<Runnable>(); Runnable mActive; Loading Loading @@ -277,15 +279,19 @@ public abstract class AsyncTask<Params, Progress, Result> { FINISHED, } private static Handler getHandler() { private static Handler getMainHandler() { synchronized (AsyncTask.class) { if (sHandler == null) { sHandler = new InternalHandler(); sHandler = new InternalHandler(Looper.getMainLooper()); } return sHandler; } } private Handler getHandler() { return mHandler; } /** @hide */ public static void setDefaultExecutor(Executor exec) { sDefaultExecutor = exec; Loading @@ -295,6 +301,28 @@ public abstract class AsyncTask<Params, Progress, Result> { * Creates a new asynchronous task. This constructor must be invoked on the UI thread. */ public AsyncTask() { this((Looper) null); } /** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. * * @hide */ public AsyncTask(@Nullable Handler handler) { this(handler != null ? handler.getLooper() : null); } /** * Creates a new asynchronous task. This constructor must be invoked on the UI thread. * * @hide */ public AsyncTask(@Nullable Looper callbackLooper) { mHandler = callbackLooper == null || callbackLooper == Looper.getMainLooper() ? getMainHandler() : new Handler(callbackLooper); mWorker = new WorkerRunnable<Params, Result>() { public Result call() throws Exception { mTaskInvoked.set(true); Loading Loading @@ -670,8 +698,8 @@ public abstract class AsyncTask<Params, Progress, Result> { } private static class InternalHandler extends Handler { public InternalHandler() { super(Looper.getMainLooper()); public InternalHandler(Looper looper) { super(looper); } @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"}) Loading
core/java/android/widget/SelectionActionModeHelper.java +3 −1 Original line number Diff line number Diff line Loading @@ -74,8 +74,9 @@ final class SelectionActionModeHelper { startActionMode(null); } else { resetTextClassificationHelper(true /* resetSelectionTag */); final TextView tv = mEditor.getTextView(); mTextClassificationAsyncTask = new TextClassificationAsyncTask( mEditor.getTextView(), tv, TIMEOUT_DURATION, adjustSelection ? mTextClassificationHelper::suggestSelection Loading Loading @@ -340,6 +341,7 @@ final class SelectionActionModeHelper { @NonNull TextView textView, int timeOut, @NonNull Supplier<SelectionResult> selectionResultSupplier, @NonNull Consumer<SelectionResult> selectionResultCallback) { super(textView != null ? textView.getHandler() : null); mTextView = Preconditions.checkNotNull(textView); mTimeOutDuration = timeOut; mSelectionResultSupplier = Preconditions.checkNotNull(selectionResultSupplier); Loading