Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25585

Android: MediaModule creates temporary files that don't delete on app exit

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 7.1.0
    • Component/s: Android
    • Labels:
    • Environment:

      Branch 6_3_X
      Tested on Galaxy S6

    • Sprint:
      2018 Sprint 04 SDK

      Description

      The results:
      Calling Ti.Media.showCamera without overlay and saveToPhotoGallery set to false, fills the appdata directory with orphan pseudo-temporary files.

      The explanation:
      When you use Ti.Media.showCamera without overlay, it calls
      launchNativeCamera(cameraOptions);
      Then, in launchNativeCamera method, it creates imageFile variable (MediaModule.java line 231)

      //Create an output file irrespective of whether saveToGallery
      		//is true or false. If false, we'll delete it later
      		File imageFile = null;
       
      		if (saveToPhotoGallery) {
      			imageFile = MediaModule.createGalleryImageFile(extension);
      		} else {
      			imageFile = MediaModule.createExternalStorageFile(extension, Environment.DIRECTORY_PICTURES, false);
      		}
      

      Well, in both cases the code ends calling

      private static File createExternalStorageFile(String extension, String type, boolean isPublic)
      

      This method creates a temporary file using the following code (MediaModule.java line 630)

      file = TiFileHelper.getInstance().getTempFile(appDir, ext, false);
      

      Well, the last argument in getTempFile method is destroyOnExit. TiFileHelper uses this flag to decide wether to include or not the resulting file in an ArrayList<File>. All files included in this list will be deleted after execution (see line 860 in TiApplication.java, method dispose).

      Ok, this is not very important as later, in MediaModule, in line 805, when processing the onResult event, the temporary file is deleted:

      if (!saveToPhotoGallery) {
      	//Create a file in the internal data directory and delete the original file
      	try {
      		File dataFile = TiFileFactory.createDataFile("tia", extension);
      		copyFile(imageFile, dataFile);
      		imageFile.delete();
      		imageFile = dataFile;
       
      	} catch(Throwable t) {
      		if (errorCallback != null) {
      			KrollDict response = new KrollDict();
      			response.putCodeAndMessage(UNKNOWN_ERROR, t.getMessage());
      			errorCallback.callAsync(getKrollObject(), response);
      		}
      		return;
      	}
      }
      

      So, the first temporary file created is deleted after have being copied, but then it's never deleted.

      You can check your appdata directory from the app and each time a photo is taken, a new "tiaxxxxxxx.jpg" file is created and never deleted. The app data size is always growing up.

        Attachments

          Activity

            People

            • Assignee:
              ybanev Yordan Banev
              Reporter:
              rfarfan Rodrigo Farfán
              Reviewer:
              Joshua Quick
              Tester:
              Samir Mohammed
            • Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code