summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan <adnan@cyngn.com>2014-08-27 17:13:28 -0700
committerAdnan <adnan@cyngn.com>2014-08-28 10:59:27 -0700
commitd0c5a7169ba60b65fd91158a1310a8443118227c (patch)
tree83ffe6b416c50d1747fef80c6f6ac3d2d1abe483
parent2ef0f2fc6d08a3e077e4425754c867e7cf3140c3 (diff)
downloadandroid_packages_providers_DownloadProvider-d0c5a7169ba60b65fd91158a1310a8443118227c.zip
android_packages_providers_DownloadProvider-d0c5a7169ba60b65fd91158a1310a8443118227c.tar.gz
android_packages_providers_DownloadProvider-d0c5a7169ba60b65fd91158a1310a8443118227c.tar.bz2
DownloadProvider: Check if the device actually supports second storage.
Change-Id: I78297ca235e058aecfd0ff5a0e990fc3004b4c77
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java2
-rwxr-xr-xsrc/com/android/providers/downloads/DownloadThread.java5
-rw-r--r--src/com/android/providers/downloads/Helpers.java6
-rw-r--r--src/com/android/providers/downloads/StorageManager.java37
4 files changed, 30 insertions, 20 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 132deb9..ed793aa 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -713,7 +713,7 @@ public final class DownloadProvider extends ContentProvider {
final String phoneStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
String sdCardStoragePath = null;
- if (StorageManager.isSecondStorageSupported()) {
+ if (StorageManager.isSecondStorageSupported(getContext())) {
sdCardStoragePath = StorageManager.getExternalStorageDirectory(getContext());
}
if (!path.startsWith(phoneStoragePath)
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java
index 88cd916..517d8f8 100755
--- a/src/com/android/providers/downloads/DownloadThread.java
+++ b/src/com/android/providers/downloads/DownloadThread.java
@@ -583,7 +583,7 @@ public class DownloadThread implements Runnable {
*/
private void writeDataToDestination(State state, byte[] data, int bytesRead, OutputStream out)
throws StopRequestException {
- mStorageManager.verifySpaceBeforeWritingToFile(
+ mStorageManager.verifySpaceBeforeWritingToFile(mContext,
mInfo.mDestination, state.mFilename, bytesRead);
boolean forceVerified = false;
@@ -595,7 +595,8 @@ public class DownloadThread implements Runnable {
// TODO: better differentiate between DRM and disk failures
if (!forceVerified) {
// couldn't write to file. are we out of space? check.
- mStorageManager.verifySpace(mInfo.mDestination, state.mFilename, bytesRead);
+ mStorageManager.verifySpace(mContext, mInfo.mDestination,
+ state.mFilename, bytesRead);
forceVerified = true;
} else {
throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index d9b38b5..0739eea 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -92,7 +92,7 @@ public class Helpers {
path = chooseFilename(url, hint, contentDisposition, contentLocation,
destination);
}
- storageManager.verifySpace(destination, path, contentLength);
+ storageManager.verifySpace(context, destination, path, contentLength);
if (DownloadDrmHelper.isDrmConvertNeeded(mimeType)) {
path = DownloadDrmHelper.modifyDrmFwLockFileExtension(path);
}
@@ -382,8 +382,8 @@ public class Helpers {
return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
|| filename.startsWith(downloadsDataDir.toString())
|| filename.startsWith(Environment.getExternalStorageDirectory().toString())
- || (StorageManager.isSecondStorageSupported() && filename.startsWith(StorageManager
- .getExternalStorageDirectory(context)));
+ || (StorageManager.isSecondStorageSupported(context)
+ && filename.startsWith(StorageManager.getExternalStorageDirectory(context)));
}
/**
diff --git a/src/com/android/providers/downloads/StorageManager.java b/src/com/android/providers/downloads/StorageManager.java
index a0ceae6..4194ec8 100644
--- a/src/com/android/providers/downloads/StorageManager.java
+++ b/src/com/android/providers/downloads/StorageManager.java
@@ -88,7 +88,7 @@ class StorageManager {
mExternalStorageDir = Environment.getExternalStorageDirectory();
mSystemCacheDir = Environment.getDownloadCacheDirectory();
startThreadToCleanupDatabaseAndPurgeFileSystem();
- if (isSecondStorageSupported()) {
+ if (isSecondStorageSupported(context)) {
sdCardStorageDir = getExternalStorageDirectory(context);
} else {
sdCardStorageDir = null;
@@ -125,17 +125,18 @@ class StorageManager {
mCleanupThread.start();
}
- void verifySpaceBeforeWritingToFile(int destination, String path, long length)
+ void verifySpaceBeforeWritingToFile(Context context, int destination, String path, long length)
throws StopRequestException {
// do this check only once for every 1MB of downloaded data
if (incrementBytesDownloadedSinceLastCheckOnSpace(length) <
FREQUENCY_OF_CHECKS_ON_SPACE_AVAILABILITY) {
return;
}
- verifySpace(destination, path, length);
+ verifySpace(context, destination, path, length);
}
- void verifySpace(int destination, String path, long length) throws StopRequestException {
+ void verifySpace(Context context, int destination, String path,
+ long length) throws StopRequestException {
resetBytesDownloadedSinceLastCheckOnSpace();
File dir = null;
if (Constants.LOGV) {
@@ -158,7 +159,7 @@ class StorageManager {
dir = mSystemCacheDir;
break;
case Downloads.Impl.DESTINATION_FILE_URI:
- if (isSecondStorageSupported() && path.startsWith(sdCardStorageDir)) {
+ if (isSecondStorageSupported(context) && path.startsWith(sdCardStorageDir)) {
dir = new File(sdCardStorageDir);
} else if (path.startsWith(mExternalStorageDir.getPath())) {
dir = mExternalStorageDir;
@@ -173,7 +174,7 @@ class StorageManager {
throw new IllegalStateException("invalid combination of destination: " + destination +
", path: " + path);
}
- findSpace(dir, length, destination);
+ findSpace(context, dir, length, destination);
}
/**
@@ -181,12 +182,12 @@ class StorageManager {
* specified by the input param(targetBytes).
* returns true if found. false otherwise.
*/
- private synchronized void findSpace(File root, long targetBytes, int destination)
- throws StopRequestException {
+ private synchronized void findSpace(Context context, File root, long targetBytes,
+ int destination) throws StopRequestException {
if (targetBytes == 0) {
return;
}
- if (!(isSecondStorageSupported() && root.getPath().startsWith(sdCardStorageDir))) {
+ if (!(isSecondStorageSupported(context) && root.getPath().startsWith(sdCardStorageDir))) {
if (destination == Downloads.Impl.DESTINATION_FILE_URI ||
destination == Downloads.Impl.DESTINATION_EXTERNAL) {
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
@@ -484,12 +485,20 @@ class StorageManager {
}
/**
- * Whether support Second Storage
- *
- * @return boolean true support Second Storage, false will be not
+ * Whether the device supports second storage
+ * @return boolean true support second storage, false does not
*/
- public static boolean isSecondStorageSupported() {
- return true;
+ public static boolean isSecondStorageSupported(Context context) {
+ android.os.storage.StorageManager storageManager =
+ (android.os.storage.StorageManager) context
+ .getSystemService(Context.STORAGE_SERVICE);
+ StorageVolume[] volumes = storageManager.getVolumeList();
+ for (int i = 0; i < volumes.length; i++) {
+ if (!volumes[i].isPrimary() && volumes[i].allowMassStorage()) {
+ return true;
+ }
+ }
+ return false;
}
public static String getExternalStorageDirectory(Context context) {