Search in sources :

Example 1 with PartUriParser

use of org.thoughtcrime.securesms.mms.PartUriParser in project Signal-Android by WhisperSystems.

the class PartProvider method openFile.

@Override
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(getContext());
    Log.w(TAG, "openFile() called!");
    if (masterSecret == null) {
        Log.w(TAG, "masterSecret was null, abandoning.");
        return null;
    }
    switch(uriMatcher.match(uri)) {
        case SINGLE_ROW:
            Log.w(TAG, "Parting out a single row...");
            try {
                PartUriParser partUri = new PartUriParser(uri);
                File tmpFile = copyPartToTemporaryFile(masterSecret, partUri.getPartId());
                ParcelFileDescriptor pdf = ParcelFileDescriptor.open(tmpFile, ParcelFileDescriptor.MODE_READ_ONLY);
                if (!tmpFile.delete()) {
                    Log.w(TAG, "Failed to delete temp file.");
                }
                return pdf;
            } catch (IOException ioe) {
                Log.w(TAG, ioe);
                throw new FileNotFoundException("Error opening file");
            }
    }
    throw new FileNotFoundException("Request for bad part.");
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) PartUriParser(org.thoughtcrime.securesms.mms.PartUriParser) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File)

Aggregations

ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 PartUriParser (org.thoughtcrime.securesms.mms.PartUriParser)1