Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java |
index 734fc90c9dc9954910add716c251cdb962289912..db8d63297c52aa8182d19c8f5890b80ab91a8144 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java |
@@ -13,6 +13,7 @@ import android.content.Intent; |
import android.net.Uri; |
import android.os.AsyncTask; |
import android.os.Build; |
+import android.os.StrictMode; |
import android.text.TextUtils; |
import android.util.Log; |
@@ -102,9 +103,15 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> { |
private void cleanUpOldWebappDirectories( |
HashSet<File> directoriesToDelete, String baseDirectory) { |
Context context = ApplicationStatus.getApplicationContext(); |
- |
- String webappDirectoryAppBaseName = |
- context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE).getName(); |
+ File webappBaseDirectory = null; |
+ |
+ // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 |
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ try { |
+ webappBaseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE); |
+ } finally { |
+ StrictMode.setThreadPolicy(oldPolicy); |
+ } |
// Figure out what WebappActivities are still listed in Android's recents menu. |
HashSet<String> liveWebapps = new HashSet<String>(); |
@@ -135,25 +142,27 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> { |
} |
} |
- // Delete all webapp directories in the main directory. |
- File dataDirectory = new File(baseDirectory); |
- File[] files = dataDirectory.listFiles(); |
- if (files != null) { |
- for (File file : files) { |
- String filename = file.getName(); |
- if (!filename.startsWith(webappDirectoryAppBaseName)) continue; |
- if (filename.length() == webappDirectoryAppBaseName.length()) continue; |
- directoriesToDelete.add(file); |
- } |
- } |
- |
- // Clean out webapp directories no longer corresponding to tasks in Recents. |
- File webappBaseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE); |
- if (webappBaseDirectory.exists()) { |
- files = webappBaseDirectory.listFiles(); |
+ if (webappBaseDirectory != null) { |
+ // Delete all webapp directories in the main directory. |
+ String webappDirectoryAppBaseName = webappBaseDirectory.getName(); |
+ File dataDirectory = new File(baseDirectory); |
+ File[] files = dataDirectory.listFiles(); |
if (files != null) { |
for (File file : files) { |
- if (!liveWebapps.contains(file.getName())) directoriesToDelete.add(file); |
+ String filename = file.getName(); |
+ if (!filename.startsWith(webappDirectoryAppBaseName)) continue; |
+ if (filename.length() == webappDirectoryAppBaseName.length()) continue; |
+ directoriesToDelete.add(file); |
+ } |
+ } |
+ |
+ // Clean out webapp directories no longer corresponding to tasks in Recents. |
+ if (webappBaseDirectory.exists()) { |
+ files = webappBaseDirectory.listFiles(); |
+ if (files != null) { |
+ for (File file : files) { |
+ if (!liveWebapps.contains(file.getName())) directoriesToDelete.add(file); |
+ } |
} |
} |
} |
@@ -166,11 +175,17 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> { |
*/ |
public static File getWebappDirectory(String identifier) { |
Context context = ApplicationStatus.getApplicationContext(); |
- File baseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE); |
- File webappDirectory = new File(baseDirectory, identifier); |
- if (!webappDirectory.exists() && !webappDirectory.mkdir()) { |
- Log.e(TAG, "Failed to create webapp directory."); |
+ // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781 |
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ try { |
+ File baseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE); |
+ File webappDirectory = new File(baseDirectory, identifier); |
+ if (!webappDirectory.exists() && !webappDirectory.mkdir()) { |
+ Log.e(TAG, "Failed to create webapp directory."); |
+ } |
+ return webappDirectory; |
+ } finally { |
+ StrictMode.setThreadPolicy(oldPolicy); |
} |
- return webappDirectory; |
} |
} |