Browse Source

优化listFiles返回为null的异常

zk 1 year ago
parent
commit
fcbffed306
1 changed files with 49 additions and 41 deletions
  1. 49 41
      app/src/main/java/com/datarecovery/master/utils/xfile/XFileSearch.java

+ 49 - 41
app/src/main/java/com/datarecovery/master/utils/xfile/XFileSearch.java

@@ -306,61 +306,67 @@ public class XFileSearch {
                     XSAFFile androidDataXSA = new XSAFFile(context, treeUri, new String[]{"Android", "data"});
                     if (androidDataXSA.exists()) {
                         XFile[] xFiles = androidDataXSA.listFiles();
-                        for (XFile x : xFiles) {
-                            XFile tag = null;
-                            for (XFile next : androidDataFiles) {
-                                try {
-                                    if (x.getPath().equals(next.getPath())) {
-                                        tag = next;
-                                        break;
+                        if (xFiles != null) {
+                            for (XFile x : xFiles) {
+                                XFile tag = null;
+                                for (XFile next : androidDataFiles) {
+                                    try {
+                                        if (x.getPath().equals(next.getPath())) {
+                                            tag = next;
+                                            break;
+                                        }
+                                    } catch (Exception ignore) {
                                     }
-                                } catch (Exception ignore) {
                                 }
-                            }
-                            if (tag == null) {
-                                allFiles.add(x);
-                            } else {
-                                androidDataFiles.remove(tag);
+                                if (tag == null) {
+                                    allFiles.add(x);
+                                } else {
+                                    androidDataFiles.remove(tag);
+                                }
                             }
                         }
                     }
                     if (androidEx.exists()) {
                         XFile[] xFiles = androidEx.listFiles();
-                        for (XFile x : xFiles) {
-                            try {
-                                if ("Android".equals(x.getName())) {
-                                    androidXSA = x;
-                                    continue;
-                                }
-                            } catch (Exception ignore) {
-                            }
-                            XFile tag = null;
-                            for (XFile next : normalFiles) {
+                        if (xFiles != null) {
+                            for (XFile x : xFiles) {
                                 try {
-                                    if (x.getPath().equals(next.getPath())) {
-                                        tag = next;
-                                        break;
+                                    if ("Android".equals(x.getName())) {
+                                        androidXSA = x;
+                                        continue;
                                     }
                                 } catch (Exception ignore) {
                                 }
-                            }
-                            if (tag == null) {
-                                allFiles.add(x);
-                            } else {
-                                normalFiles.remove(tag);
+                                XFile tag = null;
+                                for (XFile next : normalFiles) {
+                                    try {
+                                        if (x.getPath().equals(next.getPath())) {
+                                            tag = next;
+                                            break;
+                                        }
+                                    } catch (Exception ignore) {
+                                    }
+                                }
+                                if (tag == null) {
+                                    allFiles.add(x);
+                                } else {
+                                    normalFiles.remove(tag);
+                                }
                             }
                         }
                     }
                     try {
                         if (androidXSA != null && androidXSA.exists()) {
                             XFile[] xFiles = androidXSA.listFiles();
-                            for (XFile xFile : xFiles) {
-                                try {
-                                    if (xFile.getPath().contains("Android%2Fdata") || xFile.getPath().contains("Android/data")) {
-                                        continue;
+                            if (xFiles != null) {
+                                for (XFile xFile : xFiles) {
+                                    try {
+                                        if (xFile.getPath().contains("Android%2Fdata") || xFile.getPath().contains("Android/data")) {
+                                            continue;
+                                        }
+                                        allFiles.add(xFile);
+                                    } catch (Exception ignore) {
                                     }
-                                    allFiles.add(xFile);
-                                } catch (Exception ignore) {
                                 }
                             }
                         }
@@ -616,11 +622,13 @@ public class XFileSearch {
                         continue;
                     }
                     XFile[] files = file.listFiles();
-                    for (XFile childFile : files) {
-                        if (childFile == null) {
-                            continue;
+                    if (files != null) {
+                        for (XFile childFile : files) {
+                            if (childFile == null) {
+                                continue;
+                            }
+                            fileQueue.offer(childFile);
                         }
-                        fileQueue.offer(childFile);
                     }
                 } else if (fileFilter.acceptFile(file)) {
                     if (callback != null) {