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);
}
}
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;
}
}
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);
}
}
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);
}
}
});
}
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);
}
}
});
}
Aggregations