diff options
Diffstat (limited to 'src/com/android/providers/downloads/StorageManager.java')
-rw-r--r-- | src/com/android/providers/downloads/StorageManager.java | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/com/android/providers/downloads/StorageManager.java b/src/com/android/providers/downloads/StorageManager.java index deb412e7..a0ceae6a 100644 --- a/src/com/android/providers/downloads/StorageManager.java +++ b/src/com/android/providers/downloads/StorageManager.java @@ -19,6 +19,7 @@ package com.android.providers.downloads; import static com.android.providers.downloads.Constants.LOGV; import static com.android.providers.downloads.Constants.TAG; +import android.app.Activity; import android.content.ContentUris; import android.content.Context; import android.content.res.Resources; @@ -27,6 +28,7 @@ import android.database.sqlite.SQLiteException; import android.net.Uri; import android.os.Environment; import android.os.StatFs; +import android.os.storage.StorageVolume; import android.provider.Downloads; import android.text.TextUtils; import android.util.Log; @@ -77,6 +79,8 @@ class StorageManager { /** misc members */ private final Context mContext; + private static String sdCardStorageDir; + private static final String LOGTAG = "StorageManager"; public StorageManager(Context context) { mContext = context; @@ -84,6 +88,11 @@ class StorageManager { mExternalStorageDir = Environment.getExternalStorageDirectory(); mSystemCacheDir = Environment.getDownloadCacheDirectory(); startThreadToCleanupDatabaseAndPurgeFileSystem(); + if (isSecondStorageSupported()) { + sdCardStorageDir = getExternalStorageDirectory(context); + } else { + sdCardStorageDir = null; + } } /** How often should database and filesystem be cleaned up to remove spurious files @@ -149,7 +158,9 @@ class StorageManager { dir = mSystemCacheDir; break; case Downloads.Impl.DESTINATION_FILE_URI: - if (path.startsWith(mExternalStorageDir.getPath())) { + if (isSecondStorageSupported() && path.startsWith(sdCardStorageDir)) { + dir = new File(sdCardStorageDir); + } else if (path.startsWith(mExternalStorageDir.getPath())) { dir = mExternalStorageDir; } else if (path.startsWith(mDownloadDataDir.getPath())) { dir = mDownloadDataDir; @@ -175,11 +186,13 @@ class StorageManager { if (targetBytes == 0) { return; } - if (destination == Downloads.Impl.DESTINATION_FILE_URI || - destination == Downloads.Impl.DESTINATION_EXTERNAL) { - if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - throw new StopRequestException(Downloads.Impl.STATUS_DEVICE_NOT_FOUND_ERROR, - "external media not mounted"); + if (!(isSecondStorageSupported() && root.getPath().startsWith(sdCardStorageDir))) { + if (destination == Downloads.Impl.DESTINATION_FILE_URI || + destination == Downloads.Impl.DESTINATION_EXTERNAL) { + if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { + throw new StopRequestException(Downloads.Impl.STATUS_DEVICE_NOT_FOUND_ERROR, + "external media not mounted"); + } } } // is there enough space in the file system of the given param 'root'. @@ -469,4 +482,28 @@ class StorageManager { private synchronized void resetBytesDownloadedSinceLastCheckOnSpace() { mBytesDownloadedSinceLastCheckOnSpace = 0; } + + /** + * Whether support Second Storage + * + * @return boolean true support Second Storage, false will be not + */ + public static boolean isSecondStorageSupported() { + return true; + } + + public static String getExternalStorageDirectory(Context context) { + String sdCardDir = null; + 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].isRemovable() && volumes[i].allowMassStorage()) { + sdCardDir = volumes[i].getPath(); + break; + } + } + return sdCardDir; + } } |