Search in sources :

Example 16 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureCameraActivity method onPictureTaken.

@Override
public void onPictureTaken(final byte[] data, Camera camera) {
    try {
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filename)));
        out.write(data);
        out.flush();
        out.close();
        if (thumbnail != null) {
            Bitmap thumbnailBitmap = getThumbnail(getContentResolver(), filename);
            FileOutputStream fos = new FileOutputStream(thumbnail);
            thumbnailBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        }
        Intent intent = new Intent();
        intent.putExtra(FILENAME, filename);
        intent.putExtra(THUMBNAIL, thumbnail);
        intent.putExtra(MIMETYPE, "image/*");
        setResult(Activity.RESULT_OK, intent);
        finish();
    } catch (Exception e) {
        e.printStackTrace();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
    finish();
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(info.guardianproject.iocipher.FileOutputStream) Intent(android.content.Intent) BufferedOutputStream(java.io.BufferedOutputStream) File(info.guardianproject.iocipher.File) IOException(java.io.IOException)

Example 17 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class ChatSessionAdapter method downloadMedia.

public String downloadMedia(String mediaLink, String msgId, String nickname) {
    String result = null;
    try {
        Downloader dl = new Downloader();
        File fileDownload = dl.openSecureStorageFile(mContactId + "", mediaLink);
        OutputStream storageStream = new info.guardianproject.iocipher.FileOutputStream(fileDownload);
        boolean downloaded = dl.get(mediaLink, storageStream);
        if (downloaded) {
            String mimeType = dl.getMimeType();
            try {
                // boolean isVerified = getDefaultOtrChatSession().isKeyVerified(bareUsername);
                // int type = isVerified ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED : Imps.MessageType.INCOMING_ENCRYPTED;
                int type = Imps.MessageType.INCOMING;
                if (mediaLink.startsWith("aesgcm"))
                    type = Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED;
                result = SecureMediaStore.vfsUri(fileDownload.getAbsolutePath()).toString();
                insertOrUpdateChat(result);
                // Imps.deleteMessageInDb(service.getContentResolver(),msgId);
                Uri messageUri = Imps.insertMessageInDb(service.getContentResolver(), mIsGroupChat, getId(), true, nickname, result, System.currentTimeMillis(), type, 0, msgId, mimeType);
                if (// error writing to database
                messageUri == null) {
                    Log.e(TAG, "error saving message to the db: " + msgId);
                    return null;
                }
                String sanitizedPath = Uri.parse(mediaLink).getLastPathSegment();
                try {
                    int N = mRemoteListeners.beginBroadcast();
                    for (int i = 0; i < N; i++) {
                        IChatListener listener = mRemoteListeners.getBroadcastItem(i);
                        try {
                            listener.onIncomingFileTransferProgress(sanitizedPath, 100);
                        } catch (RemoteException e) {
                        // The RemoteCallbackList will take care of removing the
                        // dead listeners.
                        }
                    }
                    mRemoteListeners.finishBroadcast();
                } catch (Exception e) {
                    Log.e(TAG, "error notifying of new messages", e);
                }
            } catch (Exception e) {
                Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
            }
        }
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error downloading incoming media", e);
    }
    return result;
}
Also used : IChatListener(org.awesomeapp.messenger.service.IChatListener) OutputStream(java.io.OutputStream) Downloader(eu.siacs.conversations.Downloader) RemoteException(android.os.RemoteException) File(info.guardianproject.iocipher.File) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RemoteException(android.os.RemoteException)

Example 18 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class ChatSessionAdapter method offerData.

@Override
public boolean offerData(String offerId, final String mediaPath, final String mimeType) {
    if (TextUtils.isEmpty(mimeType))
        return false;
    Uri mediaUri = Uri.parse(mediaPath);
    if (mediaUri == null || mediaUri.getPath() == null)
        return false;
    String fileName = mediaUri.getLastPathSegment();
    java.io.InputStream fis = null;
    long fileLength = -1;
    if (mediaUri.getScheme() != null && mediaUri.getScheme().equals("vfs")) {
        info.guardianproject.iocipher.File fileLocal = new info.guardianproject.iocipher.File(mediaUri.getPath());
        if (fileLocal.exists()) {
            try {
                fis = new info.guardianproject.iocipher.FileInputStream(fileLocal);
                fileName = fileLocal.getName();
                fileLength = fileLocal.length();
            } catch (FileNotFoundException fe) {
                Log.w(TAG, "encrypted file not found on import: " + mediaUri);
                return false;
            }
        } else {
            Log.w(TAG, "encrypted file not found on import: " + mediaUri);
            return false;
        }
    } else if (mediaUri.getScheme() != null && mediaUri.getScheme().equals("content")) {
        ContentResolver cr = service.getContentResolver();
        Cursor returnCursor = cr.query(mediaUri, null, null, null, null);
        if (returnCursor != null && returnCursor.moveToFirst()) {
            int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
            int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
            fileName = returnCursor.getString(nameIndex);
            fileLength = returnCursor.getLong(sizeIndex);
            returnCursor.close();
            try {
                fis = cr.openInputStream(mediaUri);
            } catch (Exception e) {
                return false;
            }
        } else {
            return false;
        }
    } else {
        java.io.File fileLocal = new java.io.File(mediaUri.getPath());
        if (fileLocal.exists()) {
            try {
                fis = new java.io.FileInputStream(fileLocal);
                fileLength = fileLocal.length();
            } catch (FileNotFoundException fe) {
                Log.w(TAG, "file system file not found on import: " + mediaUri);
                return false;
            }
        } else {
            Log.w(TAG, "file system file not found on import: " + mediaUri);
            return false;
        }
    }
    sendMediaMessageAsync(mediaPath, mimeType, fileName, fis, fileLength);
    return true;
}
Also used : File(info.guardianproject.iocipher.File) FileNotFoundException(java.io.FileNotFoundException) Cursor(android.database.Cursor) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RemoteException(android.os.RemoteException) ContentResolver(android.content.ContentResolver) File(info.guardianproject.iocipher.File) InputStream(java.io.InputStream)

Example 19 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureCameraActivity method getThumbnail.

public Bitmap getThumbnail(ContentResolver cr, String filename) throws IOException {
    File file = new File(filename);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inInputShareable = true;
    options.inPurgeable = true;
    FileInputStream fis = new FileInputStream(file);
    BitmapFactory.decodeStream(fis, null, options);
    fis.close();
    if ((options.outWidth == -1) || (options.outHeight == -1))
        throw new IOException("Bad image " + file);
    int originalSize = (options.outHeight > options.outWidth) ? options.outHeight : options.outWidth;
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
    fis = new FileInputStream(file);
    Bitmap scaledBitmap = BitmapFactory.decodeStream(fis, null, opts);
    return scaledBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException) File(info.guardianproject.iocipher.File) FileInputStream(info.guardianproject.iocipher.FileInputStream)

Example 20 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureMediaStore method copyToVfs.

public static void copyToVfs(byte[] buf, String targetPath) throws IOException {
    File file = new File(targetPath);
    FileOutputStream out = new FileOutputStream(file);
    out.write(buf);
    out.close();
}
Also used : FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File)

Aggregations

File (info.guardianproject.iocipher.File)32 IOException (java.io.IOException)14 FileOutputStream (info.guardianproject.iocipher.FileOutputStream)6 FileInputStream (info.guardianproject.iocipher.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 Bitmap (android.graphics.Bitmap)4 Uri (android.net.Uri)4 HashMap (java.util.HashMap)4 RemoteException (android.os.RemoteException)3 RandomAccessFile (info.guardianproject.iocipher.RandomAccessFile)3 BitmapFactory (android.graphics.BitmapFactory)2 MediaDataSource (android.media.MediaDataSource)2 MediaPlayer (android.media.MediaPlayer)2 HttpRequest (cz.msebera.android.httpclient.HttpRequest)2 BasicHttpRequest (cz.msebera.android.httpclient.message.BasicHttpRequest)2 InputStream (java.io.InputStream)2 HttpMediaStreamer (org.awesomeapp.messenger.util.HttpMediaStreamer)2 OmemoFingerprint (org.jivesoftware.smackx.omemo.OmemoFingerprint)2 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2