Search in sources :

Example 6 with OpenPgpError

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

the class OpenPgpApi method executeApi.

public <T> OpenPgpDataResult<T> executeApi(Intent data, OpenPgpDataSource dataSource, OpenPgpDataSink<T> dataSink) {
    ParcelFileDescriptor input = null;
    ParcelFileDescriptor output = null;
    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();
        }
        DataSinkTransferThread<T> pumpThread = null;
        int outputPipeId = 0;
        if (dataSink != null) {
            outputPipeId = mPipeIdGen.incrementAndGet();
            output = mService.createOutputPipe(outputPipeId);
            pumpThread = ParcelFileDescriptorUtil.asyncPipeToDataSink(dataSink, output);
        }
        Intent result = executeApi(data, input, outputPipeId);
        if (pumpThread == null) {
            return new OpenPgpDataResult<>(result, null);
        }
        // wait for ALL data being pumped from remote side
        pumpThread.join();
        return new OpenPgpDataResult<>(result, pumpThread.getResult());
    } catch (Exception e) {
        Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e);
        Intent result = new Intent();
        result.putExtra(RESULT_CODE, RESULT_CODE_ERROR);
        result.putExtra(RESULT_ERROR, new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
        return new OpenPgpDataResult<>(result, null);
    } finally {
        closeLoudly(output);
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) Intent(android.content.Intent) OpenPgpError(org.openintents.openpgp.OpenPgpError) IOException(java.io.IOException)

Example 7 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) {
        Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e);
        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)

Example 8 with OpenPgpError

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

the class OpenPgpApi method executeApi.

public Intent executeApi(Intent data, InputStream is, OutputStream os) {
    ParcelFileDescriptor input = null;
    ParcelFileDescriptor output = null;
    try {
        if (is != null) {
            input = ParcelFileDescriptorUtil.pipeFrom(is);
        }
        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) {
        Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e);
        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;
    } finally {
        closeLoudly(output);
    }
}
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)

Example 9 with OpenPgpError

use of org.openintents.openpgp.OpenPgpError in project Conversations by siacs.

the class PgpEngine method hasKey.

public void hasKey(final Contact contact, final UiCallback<Contact> callback) {
    Intent params = new Intent();
    params.setAction(OpenPgpApi.ACTION_GET_KEY);
    params.putExtra(OpenPgpApi.EXTRA_KEY_ID, contact.getPgpKeyId());
    api.executeApiAsync(params, null, null, new IOpenPgpCallback() {

        @Override
        public void onReturn(Intent result) {
            switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
                case OpenPgpApi.RESULT_CODE_SUCCESS:
                    callback.success(contact);
                    return;
                case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                    callback.userInputRequried((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), contact);
                    return;
                case OpenPgpApi.RESULT_CODE_ERROR:
                    logError(contact.getAccount(), (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
                    callback.error(R.string.openpgp_error, contact);
            }
        }
    });
}
Also used : IOpenPgpCallback(org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) OpenPgpError(org.openintents.openpgp.OpenPgpError)

Example 10 with OpenPgpError

use of org.openintents.openpgp.OpenPgpError in project Conversations by siacs.

the class PgpEngine method chooseKey.

public void chooseKey(final Account account, final UiCallback<Account> callback) {
    Intent p = new Intent();
    p.setAction(OpenPgpApi.ACTION_GET_SIGN_KEY_ID);
    api.executeApiAsync(p, null, null, new IOpenPgpCallback() {

        @Override
        public void onReturn(Intent result) {
            switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, 0)) {
                case OpenPgpApi.RESULT_CODE_SUCCESS:
                    callback.success(account);
                    return;
                case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
                    callback.userInputRequried((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT), account);
                    return;
                case OpenPgpApi.RESULT_CODE_ERROR:
                    logError(account, (OpenPgpError) result.getParcelableExtra(OpenPgpApi.RESULT_ERROR));
                    callback.error(R.string.openpgp_error, account);
            }
        }
    });
}
Also used : IOpenPgpCallback(org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) OpenPgpError(org.openintents.openpgp.OpenPgpError)

Aggregations

OpenPgpError (org.openintents.openpgp.OpenPgpError)12 Intent (android.content.Intent)10 IOException (java.io.IOException)7 PendingIntent (android.app.PendingIntent)6 OutputStream (java.io.OutputStream)4 IOpenPgpCallback (org.openintents.openpgp.util.OpenPgpApi.IOpenPgpCallback)4 ParcelFileDescriptor (android.os.ParcelFileDescriptor)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)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 TextView (android.widget.TextView)1 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)1 MessagingException (com.fsck.k9.mail.MessagingException)1