diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2011-01-06 18:39:33 -0800 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2011-01-07 09:23:10 -0800 |
commit | cd3676e7b835653b04d4f66251a63749e7603f5b (patch) | |
tree | fe86f426176fa32d8b671b62dd37d334596003fb /core/java/android/content | |
parent | 100744fa54e14be62abd211996b5dfed60de1fa4 (diff) | |
download | frameworks_base-cd3676e7b835653b04d4f66251a63749e7603f5b.zip frameworks_base-cd3676e7b835653b04d4f66251a63749e7603f5b.tar.gz frameworks_base-cd3676e7b835653b04d4f66251a63749e7603f5b.tar.bz2 |
Adding AsyncTaskLoader.waitForLoader() for testing
Change-Id: I8a4c13d48c9deca70594be58beafb68f08da65ea
Diffstat (limited to 'core/java/android/content')
-rw-r--r-- | core/java/android/content/AsyncTaskLoader.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/core/java/android/content/AsyncTaskLoader.java b/core/java/android/content/AsyncTaskLoader.java index d6bc959..01a2912 100644 --- a/core/java/android/content/AsyncTaskLoader.java +++ b/core/java/android/content/AsyncTaskLoader.java @@ -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()); + } + } + } } |