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

Commit cd3676e7 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Adding AsyncTaskLoader.waitForLoader() for testing

Change-Id: I8a4c13d48c9deca70594be58beafb68f08da65ea
parent 100744fa
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -43586,6 +43586,17 @@
<parameter name="data" type="D">
</parameter>
</method>
<method name="waitForLoader"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
</class>
<class name="BroadcastReceiver"
 extends="java.lang.Object"
+28 −1
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package android.content;

import android.os.AsyncTask;
import android.util.Log;

import java.util.concurrent.ExecutionException;

/**
 * Abstract Loader that provides an {@link AsyncTask} to do the work.
@@ -24,6 +27,9 @@ import android.os.AsyncTask;
 * @param <D> the data type to be loaded.
 */
public abstract class AsyncTaskLoader<D> extends Loader<D> {

    private static final String TAG = "AsyncTaskLoader";

    final class LoadTask extends AsyncTask<Void, Void, D> {

        private D result;
@@ -47,7 +53,7 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
        }
    }

    LoadTask mTask;
    volatile LoadTask mTask;

    public AsyncTaskLoader(Context context) {
        super(context);
@@ -105,4 +111,25 @@ public abstract class AsyncTaskLoader<D> extends Loader<D> {
     * @return the result of the load
     */
    public abstract D loadInBackground();

    /**
     * Locks the current thread until the loader completes the current load
     * operation. Returns immediately if there is no load operation running.
     * Should not be called from the UI thread.
     * <p>
     * Used for testing.
     */
    public void waitForLoader() {
        LoadTask task = mTask;
        if (task != null) {
            try {
                task.get();
            } catch (InterruptedException e) {
                Log.w(TAG, e);
            } catch (ExecutionException e) {
                throw new RuntimeException("An error occured while executing waitForLoader()",
                        e.getCause());
            }
        }
    }
}