Merge "Mark otherwise unused method as @VisibleForTesting" into ub-mail-master
This commit is contained in:
commit
822f17d6c1
@ -18,6 +18,8 @@ package com.android.emailcommon.utility;
|
|||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -31,7 +33,7 @@ import java.util.concurrent.Executor;
|
|||||||
* in onDestroy() or similar places.
|
* in onDestroy() or similar places.
|
||||||
* - Instead of {@link AsyncTask#onPostExecute}, it has {@link #onSuccess(Object)}, as the
|
* - Instead of {@link AsyncTask#onPostExecute}, it has {@link #onSuccess(Object)}, as the
|
||||||
* regular {@link AsyncTask#onPostExecute} is a bit hard to predict when it'll be called and
|
* regular {@link AsyncTask#onPostExecute} is a bit hard to predict when it'll be called and
|
||||||
* whel it won't.
|
* when it won't.
|
||||||
*
|
*
|
||||||
* Note this class is missing some of the {@link AsyncTask} features, e.g. it lacks
|
* Note this class is missing some of the {@link AsyncTask} features, e.g. it lacks
|
||||||
* {@link AsyncTask#onProgressUpdate}. Add these when necessary.
|
* {@link AsyncTask#onProgressUpdate}. Add these when necessary.
|
||||||
@ -43,7 +45,7 @@ public abstract class EmailAsyncTask<Params, Progress, Result> {
|
|||||||
/**
|
/**
|
||||||
* Tracks {@link EmailAsyncTask}.
|
* Tracks {@link EmailAsyncTask}.
|
||||||
*
|
*
|
||||||
* Call {@link #cancellAllInterrupt()} to cancel all tasks registered.
|
* Call {@link #cancelAllInterrupt()} to cancel all tasks registered.
|
||||||
*/
|
*/
|
||||||
public static class Tracker {
|
public static class Tracker {
|
||||||
private final LinkedList<EmailAsyncTask<?, ?, ?>> mTasks =
|
private final LinkedList<EmailAsyncTask<?, ?, ?>> mTasks =
|
||||||
@ -64,7 +66,8 @@ public abstract class EmailAsyncTask<Params, Progress, Result> {
|
|||||||
/**
|
/**
|
||||||
* Cancel all registered tasks.
|
* Cancel all registered tasks.
|
||||||
*/
|
*/
|
||||||
public void cancellAllInterrupt() {
|
@VisibleForTesting
|
||||||
|
public void cancelAllInterrupt() {
|
||||||
synchronized (mTasks) {
|
synchronized (mTasks) {
|
||||||
for (EmailAsyncTask<?, ?, ?> task : mTasks) {
|
for (EmailAsyncTask<?, ?, ?> task : mTasks) {
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
@ -212,7 +215,7 @@ public abstract class EmailAsyncTask<Params, Progress, Result> {
|
|||||||
return executeInternal(SERIAL_EXECUTOR, true, params);
|
return executeInternal(SERIAL_EXECUTOR, true, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final EmailAsyncTask<Params, Progress, Result> executeInternal(Executor executor,
|
private EmailAsyncTask<Params, Progress, Result> executeInternal(Executor executor,
|
||||||
boolean cancelPrevious, Params... params) {
|
boolean cancelPrevious, Params... params) {
|
||||||
if (cancelPrevious) {
|
if (cancelPrevious) {
|
||||||
if (mTracker == null) {
|
if (mTracker == null) {
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.emailcommon.utility;
|
package com.android.emailcommon.utility;
|
||||||
|
|
||||||
import com.android.emailcommon.utility.EmailAsyncTask.Tracker;
|
|
||||||
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.test.MoreAsserts;
|
import android.test.MoreAsserts;
|
||||||
|
|
||||||
@ -70,7 +68,7 @@ public class EmailAsyncTaskTests extends AndroidTestCase {
|
|||||||
// Task 2 and 4 are still registered.
|
// Task 2 and 4 are still registered.
|
||||||
|
|
||||||
// Cancel all left
|
// Cancel all left
|
||||||
tracker.cancellAllInterrupt();
|
tracker.cancelAllInterrupt();
|
||||||
|
|
||||||
// Check if they're canceled
|
// Check if they're canceled
|
||||||
assertEquals(0, tracker.getTaskCountForTest());
|
assertEquals(0, tracker.getTaskCountForTest());
|
||||||
|
Loading…
Reference in New Issue
Block a user