From 6916b03e022b7ae391a1ed66a857db6e80b04c65 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Sun, 19 Dec 2010 20:31:00 -0800 Subject: [PATCH] if a download dir doesn't exist, create it or fail fast in HC, using DownloadManager public API, download directories named by the constants Environment.DOWNLOAD_* may ot exist. theyneed to be created or the download request should fail ASAP. bug:3297328 Change-Id: Ic87023d8fe98bd240744f66607a5400b7825e17e --- core/java/android/app/DownloadManager.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java index a24375eba6213..12f4a1868f6a5 100644 --- a/core/java/android/app/DownloadManager.java +++ b/core/java/android/app/DownloadManager.java @@ -453,7 +453,19 @@ public class DownloadManager { * @return this object */ public Request setDestinationInExternalPublicDir(String dirType, String subPath) { - setDestinationFromBase(Environment.getExternalStoragePublicDirectory(dirType), subPath); + File file = Environment.getExternalStoragePublicDirectory(dirType); + if (file.exists()) { + if (!file.isDirectory()) { + throw new IllegalStateException(file.getAbsolutePath() + + " already exists and is not a directory"); + } + } else { + if (!file.mkdir()) { + throw new IllegalStateException("Unable to create directory: "+ + file.getAbsolutePath()); + } + } + setDestinationFromBase(file, subPath); return this; }