Merge "Update DocsUI to use AuthenticationRequiredException instead." into arc-apps
diff --git a/src/com/android/documentsui/RecentsLoader.java b/src/com/android/documentsui/RecentsLoader.java
index e5827b3..0da169a 100644
--- a/src/com/android/documentsui/RecentsLoader.java
+++ b/src/com/android/documentsui/RecentsLoader.java
@@ -297,6 +297,7 @@
         public final List<String> rootIds;
 
         private Cursor[] mCursors;
+        private boolean mIsClosed = false;
 
         public RecentsTask(String authority, List<String> rootIds) {
             this.authority = authority;
@@ -320,7 +321,11 @@
             }
         }
 
-        public void runInternal() {
+        public synchronized void runInternal() {
+            if (mIsClosed) {
+                return;
+            }
+
             ContentProviderClient client = null;
             try {
                 client = DocumentsApplication.acquireUnstableProviderOrThrow(
@@ -362,10 +367,16 @@
         }
 
         @Override
-        public void close() throws IOException {
+        public synchronized void close() throws IOException {
+            if (mCursors == null) {
+                return;
+            }
+
             for (Cursor cursor : mCursors) {
                 IoUtils.closeQuietly(cursor);
             }
+
+            mIsClosed = true;
         }
     }
 }