Fixed crash when downloading media files of feed with invalid characters

in title
This commit is contained in:
daniel oeh 2012-07-14 15:51:03 +02:00
parent 96d9421970
commit 072222763b
2 changed files with 9 additions and 14 deletions

View File

@ -24,7 +24,7 @@ import android.os.RemoteException;
import android.content.Intent; import android.content.Intent;
import android.webkit.URLUtil; import android.webkit.URLUtil;
public class DownloadRequester { public class DownloadRequester {// TODO handle externalstorage missing
private static final String TAG = "DownloadRequester"; private static final String TAG = "DownloadRequester";
private static final int currentApi = android.os.Build.VERSION.SDK_INT; private static final int currentApi = android.os.Build.VERSION.SDK_INT;
@ -32,7 +32,6 @@ public class DownloadRequester {
public static String EXTRA_ITEM_ID = "extra.de.danoeh.antennapod.storage.item_id"; public static String EXTRA_ITEM_ID = "extra.de.danoeh.antennapod.storage.item_id";
public static String ACTION_DOWNLOAD_QUEUED = "action.de.danoeh.antennapod.storage.downloadQueued"; public static String ACTION_DOWNLOAD_QUEUED = "action.de.danoeh.antennapod.storage.downloadQueued";
private static boolean STORE_ON_SD = true; private static boolean STORE_ON_SD = true;
public static String IMAGE_DOWNLOADPATH = "images/"; public static String IMAGE_DOWNLOADPATH = "images/";
@ -77,7 +76,7 @@ public class DownloadRequester {
// TODO Set Allowed Network Types // TODO Set Allowed Network Types
DownloadManager manager = (DownloadManager) context DownloadManager manager = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE); .getSystemService(Context.DOWNLOAD_SERVICE);
long downloadId = manager.enqueue(request); long downloadId = manager.enqueue(request);
item.setDownloadId(downloadId); item.setDownloadId(downloadId);
item.setFile_url(dest.toString()); item.setFile_url(dest.toString());
@ -125,7 +124,7 @@ public class DownloadRequester {
notifyDownloadService(context); notifyDownloadService(context);
} }
} }
/** Cancels all running downloads */ /** Cancels all running downloads */
public void cancelAllDownloads(Context context) { public void cancelAllDownloads(Context context) {
Log.d(TAG, "Cancelling all running downloads"); Log.d(TAG, "Cancelling all running downloads");
@ -149,7 +148,7 @@ public class DownloadRequester {
} }
return null; return null;
} }
/** Returns true if there is at least one Feed in the downloads queue. */ /** Returns true if there is at least one Feed in the downloads queue. */
public boolean isDownloadingFeeds() { public boolean isDownloadingFeeds() {
for (FeedFile f : downloads) { for (FeedFile f : downloads) {
@ -159,7 +158,7 @@ public class DownloadRequester {
} }
return false; return false;
} }
/** Checks if feedfile is in the downloads list */ /** Checks if feedfile is in the downloads list */
public boolean isDownloadingFile(FeedFile item) { public boolean isDownloadingFile(FeedFile item) {
for (FeedFile f : downloads) { for (FeedFile f : downloads) {
@ -201,11 +200,9 @@ public class DownloadRequester {
} }
public String getMediafilePath(Context context, FeedMedia media) { public String getMediafilePath(Context context, FeedMedia media) {
return context File externalStorage = context.getExternalFilesDir(MEDIA_DOWNLOADPATH
.getExternalFilesDir( + NumberGenerator.generateLong(media.getItem().getFeed().getTitle()) + "/");
MEDIA_DOWNLOADPATH return externalStorage.toString();
+ media.getItem().getFeed().getTitle() + "/")
.toString();
} }
public String getMediafilename(FeedMedia media) { public String getMediafilename(FeedMedia media) {

View File

@ -18,8 +18,6 @@ public final class NumberGenerator {
* @return The generated random value * @return The generated random value
* */ * */
public static long generateLong(final String strSeed) { public static long generateLong(final String strSeed) {
long seed = (long) strSeed.hashCode(); return strSeed.hashCode();
Log.d(TAG, "Taking " + seed + " as seed.");
return new Random(seed).nextLong();
} }
} }