| Index: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
|
| index 048ebcc10535ae18a13604c119f368e0cbbfe824..7b6260632e88c874adaa009ee37b2acf45fb8188 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/DownloadUtils.java
|
| @@ -23,8 +23,8 @@ import android.text.TextUtils;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.ApplicationStatus;
|
| -import org.chromium.base.ContentUriUtils;
|
| import org.chromium.base.ContextUtils;
|
| +import org.chromium.base.FileUtils;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.VisibleForTesting;
|
| import org.chromium.base.metrics.RecordHistogram;
|
| @@ -458,23 +458,15 @@ public class DownloadUtils {
|
| public static Uri getUriForItem(File file) {
|
| Uri uri = null;
|
|
|
| - // #getContentUriFromFile causes a disk read when it calls into FileProvider#getUriForFile.
|
| - // Obtaining a content URI is on the critical path for creating a share intent after the
|
| - // user taps on the share button, so even if we were to run this method on a background
|
| - // thread we would have to wait. As it depends on user-selected items, we cannot
|
| - // know/preload which URIs we need until the user presses share.
|
| + // FileUtils.getUriForFile() causes a disk read when it calls into
|
| + // FileProvider#getUriForFile. Obtaining a content URI is on the critical path for creating
|
| + // a share intent after the user taps on the share button, so even if we were to run this
|
| + // method on a background thread we would have to wait. As it depends on user-selected
|
| + // items, we cannot know/preload which URIs we need until the user presses share.
|
| StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
| - try {
|
| - // Try to obtain a content:// URI, which is preferred to a file:// URI so that
|
| - // receiving apps don't attempt to determine the file's mime type (which often fails).
|
| - uri = ContentUriUtils.getContentUriFromFile(ContextUtils.getApplicationContext(), file);
|
| - } catch (IllegalArgumentException e) {
|
| - Log.e(TAG, "Could not create content uri: " + e);
|
| - }
|
| + uri = FileUtils.getUriForFile(file);
|
| StrictMode.setThreadPolicy(oldPolicy);
|
|
|
| - if (uri == null) uri = Uri.fromFile(file);
|
| -
|
| return uri;
|
| }
|
|
|
| @@ -487,7 +479,6 @@ public class DownloadUtils {
|
| */
|
| public static boolean openFile(File file, String mimeType, boolean isOffTheRecord) {
|
| Context context = ContextUtils.getApplicationContext();
|
| - Intent viewIntent = createViewIntentForDownloadItem(getUriForItem(file), mimeType);
|
| DownloadManagerService service = DownloadManagerService.getDownloadManagerService(context);
|
|
|
| // Check if Chrome should open the file itself.
|
| @@ -506,6 +497,11 @@ public class DownloadUtils {
|
|
|
| // Check if any apps can open the file.
|
| try {
|
| + // TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode.
|
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
| + Uri uri = ApiCompatibilityUtils.getUriForDownloadedFile(file);
|
| + StrictMode.setThreadPolicy(oldPolicy);
|
| + Intent viewIntent = createViewIntentForDownloadItem(uri, mimeType);
|
| context.startActivity(viewIntent);
|
| return true;
|
| } catch (ActivityNotFoundException e) {
|
|
|