Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25585] Android: MediaModule creates temporary files that don't delete on app exit. #9666

Merged
merged 15 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
Expand All @@ -22,6 +23,7 @@
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.util.TiTempFileHelper;
import org.appcelerator.titanium.ContextSpecific;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
Expand Down Expand Up @@ -176,6 +178,7 @@ public class MediaModule extends KrollModule implements Handler.Callback

private static String mediaType = MEDIA_TYPE_PHOTO;
private static String extension = ".jpg";
private TiTempFileHelper tempFileHelper;

private static class ApiLevel16
{
Expand All @@ -194,6 +197,7 @@ public static void setIntentClipData(Intent intent, ClipData data)
public MediaModule()
{
super();
tempFileHelper = new TiTempFileHelper(TiApplication.getInstance());
}

@Kroll.method
Expand Down Expand Up @@ -871,7 +875,7 @@ public void onResult(Activity activity, int requestCode, int resultCode, Intent
if (!saveToPhotoGallery) {
//Create a file in the internal data directory and delete the original file
try {
File dataFile = TiFileFactory.createDataFile("tia", extension);
File dataFile = tempFileHelper.createTempFile("tia", extension);
copyFile(imageFile, dataFile);
imageFile.delete();
imageFile = dataFile;
Expand All @@ -896,6 +900,9 @@ public void onResult(Activity activity, int requestCode, int resultCode, Intent
try {
TiFile theFile = new TiFile(imageFile, imageFile.toURI().toURL().toExternalForm(), false);
TiBlob theBlob = TiBlob.blobFromFile(theFile);
if (!saveToPhotoGallery) {
TiFileHelper.getInstance().destroyOnExit(imageFile);
}
KrollDict response = MediaModule.createDictForImage(theBlob, theBlob.getMimeType());
if (successCallback != null) {
successCallback.callAsync(getKrollObject(), response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ public byte[] getBytes()
}
}
}
break;
default:
throw new IllegalArgumentException("Unknown Blob type id " + type);
}
Expand Down