Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfe7d219 authored by Jeff Brown's avatar Jeff Brown Committed by Android Git Automerger
Browse files

am bba231d7: Explicitly bind AsyncTask to main looper.

* commit 'bba231d7':
  Explicitly bind AsyncTask to main looper.
parents 73a7f286 bba231d7
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -5223,8 +5223,6 @@ public final class ActivityThread {
            sMainThreadHandler = thread.getHandler();
        }

        AsyncTask.init();

        if (false) {
            Looper.myLooper().setMessageLogging(new
                    LogPrinter(Log.DEBUG, "ActivityThread"));
+0 −6
Original line number Diff line number Diff line
@@ -1659,12 +1659,6 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
    }

    private void attachInfo(Context context, ProviderInfo info, boolean testing) {
        /*
         * We may be using AsyncTask from binder threads.  Make it init here
         * so its static handler is on the main thread.
         */
        AsyncTask.init();

        mNoPerms = testing;

        /*
+16 −8
Original line number Diff line number Diff line
@@ -209,9 +209,9 @@ public abstract class AsyncTask<Params, Progress, Result> {
    private static final int MESSAGE_POST_RESULT = 0x1;
    private static final int MESSAGE_POST_PROGRESS = 0x2;

    private static final InternalHandler sHandler = new InternalHandler();

    private static volatile Executor sDefaultExecutor = SERIAL_EXECUTOR;
    private static InternalHandler sHandler;

    private final WorkerRunnable<Params, Result> mWorker;
    private final FutureTask<Result> mFuture;

@@ -265,9 +265,13 @@ public abstract class AsyncTask<Params, Progress, Result> {
        FINISHED,
    }

    /** @hide Used to force static handler to be created. */
    public static void init() {
        sHandler.getLooper();
    private static Handler getHandler() {
        synchronized (AsyncTask.class) {
            if (sHandler == null) {
                sHandler = new InternalHandler();
            }
            return sHandler;
        }
    }

    /** @hide */
@@ -315,7 +319,7 @@ public abstract class AsyncTask<Params, Progress, Result> {

    private Result postResult(Result result) {
        @SuppressWarnings("unchecked")
        Message message = sHandler.obtainMessage(MESSAGE_POST_RESULT,
        Message message = getHandler().obtainMessage(MESSAGE_POST_RESULT,
                new AsyncTaskResult<Result>(this, result));
        message.sendToTarget();
        return result;
@@ -620,7 +624,7 @@ public abstract class AsyncTask<Params, Progress, Result> {
     */
    protected final void publishProgress(Progress... values) {
        if (!isCancelled()) {
            sHandler.obtainMessage(MESSAGE_POST_PROGRESS,
            getHandler().obtainMessage(MESSAGE_POST_PROGRESS,
                    new AsyncTaskResult<Progress>(this, values)).sendToTarget();
        }
    }
@@ -635,10 +639,14 @@ public abstract class AsyncTask<Params, Progress, Result> {
    }

    private static class InternalHandler extends Handler {
        public InternalHandler() {
            super(Looper.getMainLooper());
        }

        @SuppressWarnings({"unchecked", "RawUseOfParameterizedType"})
        @Override
        public void handleMessage(Message msg) {
            AsyncTaskResult result = (AsyncTaskResult) msg.obj;
            AsyncTaskResult<?> result = (AsyncTaskResult<?>) msg.obj;
            switch (msg.what) {
                case MESSAGE_POST_RESULT:
                    // There is only one result