Search in sources :

Example 16 with OpenPgpError

use of org.openintents.openpgp.OpenPgpError in project k-9 by k9mail.

the class OpenPgpApi method executeApi.

public Intent executeApi(Intent data, OpenPgpDataSource dataSource, OutputStream os) {
    ParcelFileDescriptor input = null;
    ParcelFileDescriptor output;
    try {
        if (dataSource != null) {
            Long expectedSize = dataSource.getSizeForProgress();
            if (expectedSize != null) {
                data.putExtra(EXTRA_DATA_LENGTH, (long) expectedSize);
            } else {
                data.removeExtra(EXTRA_PROGRESS_MESSENGER);
            }
            input = dataSource.startPumpThread();
        }
        Thread pumpThread = null;
        int outputPipeId = 0;
        if (os != null) {
            outputPipeId = mPipeIdGen.incrementAndGet();
            output = mService.createOutputPipe(outputPipeId);
            pumpThread = ParcelFileDescriptorUtil.pipeTo(os, output);
        }
        Intent result = executeApi(data, input, outputPipeId);
        // wait for ALL data being pumped from remote side
        if (pumpThread != null) {
            pumpThread.join();
        }
        return result;
    } catch (Exception e) {
        Timber.e(e, "Exception in executeApi call");
        Intent result = new Intent();
        result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
        result.putExtra(RESULT_ERROR, new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
        return result;
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) Intent(android.content.Intent) OpenPgpError(org.openintents.openpgp.OpenPgpError) IOException(java.io.IOException) DataSourceTransferThread(org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSourceTransferThread) DataSinkTransferThread(org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSinkTransferThread)

Aggregations

OpenPgpError (org.openintents.openpgp.OpenPgpError)16 Intent (android.content.Intent)13 IOException (java.io.IOException)11 PendingIntent (android.app.PendingIntent)10 OutputStream (java.io.OutputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 ParcelFileDescriptor (android.os.ParcelFileDescriptor)3 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)3 MessagingException (com.fsck.k9.mail.MessagingException)2 EOLConvertingOutputStream (com.fsck.k9.mail.filter.EOLConvertingOutputStream)2 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)2 ArrayList (java.util.ArrayList)2 DataSinkTransferThread (org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSinkTransferThread)2 DataSourceTransferThread (org.openintents.openpgp.util.ParcelFileDescriptorUtil.DataSourceTransferThread)2 View (android.view.View)1 ImageView (android.widget.ImageView)1