浏览代码

getExternalFilesDir(null) an be null --> preventing NPE

Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>
tobiaskaminsky 7 年之前
父节点
当前提交
f080bdb70e
共有 1 个文件被更改,包括 13 次插入7 次删除
  1. 13 7
      src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java

+ 13 - 7
src/main/java/com/owncloud/android/datastorage/DataStorageProvider.java

@@ -111,13 +111,19 @@ public class DataStorageProvider {
 
         // Add external storage directory if available.
         if (isExternalStorageWritable()) {
-            storagePoint = new StoragePoint();
-            storagePoint.setPath(MainApp.getAppContext().getExternalFilesDir(null).getAbsolutePath());
-            storagePoint.setDescription(MainApp.getAppContext().getExternalFilesDir(null).getAbsolutePath());
-            storagePoint.setPrivacyType(StoragePoint.PrivacyType.PRIVATE);
-            storagePoint.setStorageType(StoragePoint.StorageType.EXTERNAL);
-            if (!paths.contains(MainApp.getAppContext().getExternalFilesDir(null).getAbsolutePath())) {
-                mCachedStoragePoints.add(storagePoint);
+            File externalFilesDir = MainApp.getAppContext().getExternalFilesDir(null);
+
+            if (externalFilesDir != null) {
+                String externalFilesDirPath = externalFilesDir.getAbsolutePath();
+
+                storagePoint = new StoragePoint();
+                storagePoint.setPath(externalFilesDirPath);
+                storagePoint.setDescription(externalFilesDirPath);
+                storagePoint.setPrivacyType(StoragePoint.PrivacyType.PRIVATE);
+                storagePoint.setStorageType(StoragePoint.StorageType.EXTERNAL);
+                if (!paths.contains(externalFilesDirPath)) {
+                    mCachedStoragePoints.add(storagePoint);
+                }
             }
         }