Browse Source

Merge pull request #2405 from nextcloud/closeCursorPart2

android.database.CursorWindowAllocationException
Tobias Kaminsky 7 years ago
parent
commit
267fa1e134

+ 1 - 1
scripts/lint/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 132 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 133 warnings</span>

+ 9 - 7
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -2161,14 +2161,16 @@ public class FileDataStorageManager {
             );
         }
 
-        if (c != null && c.moveToFirst()) {
-            do {
-                OCFile child = createFileInstanceFromVirtual(c);
+        if (c != null) {
+            if (c.moveToFirst()) {
+                do {
+                    OCFile child = createFileInstanceFromVirtual(c);
 
-                if (child != null) {
-                    ocFiles.add(child);
-                }
-            } while (c.moveToNext());
+                    if (child != null) {
+                        ocFiles.add(child);
+                    }
+                } while (c.moveToNext());
+            }
             c.close();
         }
 

+ 26 - 24
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -152,31 +152,33 @@ public class FileContentProvider extends ContentProvider {
             }
             */
                 Cursor children = query(uri, null, null, null, null);
-                if (children != null && children.moveToFirst()) {
-                    long childId;
-                    boolean isDir;
-                    while (!children.isAfterLast()) {
-                        childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
-                        isDir = MimeType.DIRECTORY.equals(children.getString(
-                                children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
-                        ));
-                        //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
-                        if (isDir) {
-                            count += delete(
-                                    db,
-                                    ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
-                                    null,
-                                    null
-                            );
-                        } else {
-                            count += delete(
-                                    db,
-                                    ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
-                                    null,
-                                    null
-                            );
+                if (children != null) {
+                    if (children.moveToFirst()) {
+                        long childId;
+                        boolean isDir;
+                        while (!children.isAfterLast()) {
+                            childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
+                            isDir = MimeType.DIRECTORY.equals(children.getString(
+                                    children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
+                            ));
+                            //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
+                            if (isDir) {
+                                count += delete(
+                                        db,
+                                        ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
+                                        null,
+                                        null
+                                );
+                            } else {
+                                count += delete(
+                                        db,
+                                        ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
+                                        null,
+                                        null
+                                );
+                            }
+                            children.moveToNext();
                         }
-                        children.moveToNext();
                     }
                     children.close();
                 } /*else {