From bfa9a38eda14c224088ed1d11fe126c5762e33ce Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Thu, 6 Mar 2014 12:23:52 -0800 Subject: [PATCH] Bug 942611 - Store temp files in Android's cache dir. r=rewman --- mobile/android/base/FilePicker.java | 2 +- .../android/base/FilePickerResultHandler.java | 29 +++++++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/mobile/android/base/FilePicker.java b/mobile/android/base/FilePicker.java index 8c5a1dbdd76..7f965d6b134 100644 --- a/mobile/android/base/FilePicker.java +++ b/mobile/android/base/FilePicker.java @@ -202,7 +202,7 @@ public class FilePicker implements GeckoEventListener { * pick and launch the file picker, but will throw away the result. */ protected void showFilePickerAsync(String mimeType, final ResultHandler handler) { - final FilePickerResultHandler fileHandler = new FilePickerResultHandler(handler); + final FilePickerResultHandler fileHandler = new FilePickerResultHandler(handler, mContext); getFilePickerIntentAsync(mimeType, fileHandler, new IntentHandler() { @Override public void gotIntent(Intent intent) { diff --git a/mobile/android/base/FilePickerResultHandler.java b/mobile/android/base/FilePickerResultHandler.java index c0446983d1e..84abeedb41e 100644 --- a/mobile/android/base/FilePickerResultHandler.java +++ b/mobile/android/base/FilePickerResultHandler.java @@ -9,6 +9,7 @@ import org.mozilla.gecko.util.ActivityResultHandler; import android.app.Activity; import android.content.ContentResolver; +import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -32,31 +33,25 @@ import java.util.Queue; class FilePickerResultHandler implements ActivityResultHandler { private static final String LOGTAG = "GeckoFilePickerResultHandler"; + private static final String UPLOADS_DIR = "uploads"; - protected final Queue mFilePickerResult; - protected final FilePicker.ResultHandler mHandler; + protected final FilePicker.ResultHandler handler; + private final File cacheDir; // this code is really hacky and doesn't belong anywhere so I'm putting it here for now // until I can come up with a better solution. private String mImageName = ""; - public FilePickerResultHandler(Queue resultQueue) { - mFilePickerResult = resultQueue; - mHandler = null; - } - /* Use this constructor to asynchronously listen for results */ - public FilePickerResultHandler(FilePicker.ResultHandler handler) { - mFilePickerResult = null; - mHandler = handler; + public FilePickerResultHandler(FilePicker.ResultHandler handler, Context context) { + cacheDir = new File(context.getCacheDir(), UPLOADS_DIR); + this.handler = handler; } private void sendResult(String res) { - if (mFilePickerResult != null) - mFilePickerResult.offer(res); - - if (mHandler != null) - mHandler.gotFile(res); + if (handler != null) { + handler.gotFile(res); + } } @Override @@ -192,7 +187,9 @@ class FilePickerResultHandler implements ActivityResultHandler { // Now write the data to the temp file try { - File file = File.createTempFile(fileName, fileExt, GeckoLoader.getGREDir(GeckoAppShell.getContext())); + cacheDir.mkdir(); + + File file = File.createTempFile(fileName, fileExt, cacheDir); FileOutputStream fos = new FileOutputStream(file); InputStream is = cr.openInputStream(mUri); byte[] buf = new byte[4096];