Skip to content

Commit

Permalink
Merge pull request #9666 from ypbnv/TIMOB-25585
Browse files Browse the repository at this point in the history
[TIMOB-25585] Android: MediaModule creates temporary files that don't delete on app exit.
  • Loading branch information
ssjsamir committed Feb 23, 2018
2 parents 1e60860 + c1867bf commit bb22d56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit bb22d56

Please sign in to comment.